Advertisement
Spocoman

Excursion Calculator

Sep 5th, 2024
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int personCount = Integer.parseInt(scanner.nextLine());
  7.         String season = scanner.nextLine();
  8.         double personPrice;
  9.  
  10.         if (season.equals("spring")) {
  11.             if (personCount <= 5) {
  12.                 personPrice = 50.00;
  13.             } else {
  14.                 personPrice = 48.00;
  15.             }
  16.         } else if (season.equals("summer")) {
  17.             if (personCount <= 5) {
  18.                 personPrice = 48.50;
  19.             } else {
  20.                 personPrice = 45.00;
  21.             }
  22.         } else if (season.equals("autumn")) {
  23.             if (personCount <= 5) {
  24.                 personPrice = 60.00;
  25.             } else {
  26.                 personPrice = 49.50;
  27.             }
  28.         } else {
  29.             if (personCount <= 5) {
  30.                 personPrice = 86.00;
  31.             } else {
  32.                 personPrice = 85.00;
  33.             }
  34.         }
  35.  
  36.         if (season.equals("summer")) {
  37.             personPrice *= 0.85;
  38.         } else if (season.equals("winter")) {
  39.             personPrice *= 1.08;
  40.         }
  41.  
  42.         System.out.printf("%.2f leva.", personPrice * personCount);
  43.     }
  44. }
  45.  
  46. ИЛИ:
  47.  
  48. import java.util.Scanner;
  49.  
  50. public class Main {
  51.     public static void main(String[] args) {
  52.         Scanner scanner = new Scanner(System.in);
  53.         int personCount = Integer.parseInt(scanner.nextLine());
  54.         String season = scanner.nextLine();
  55.  
  56.         double personPrice = switch (season) {
  57.             case "spring" -> personCount <= 5 ? 50.00 : 48.00;
  58.             case "summer" -> personCount <= 5 ? 48.50 : 45.00;
  59.             case "autumn" -> personCount <= 5 ? 60.00 : 49.50;
  60.             case "winter" -> personCount <= 5 ? 86.00 : 85.00;
  61.             default -> 0;
  62.         };
  63.  
  64.         personPrice *=
  65.                 season.equals("summer") ? 0.85
  66.                         : season.equals("winter") ? 1.08 : 1;
  67.  
  68.         System.out.printf("%.2f leva.", personPrice * personCount);
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement