Advertisement
Spocoman

Cruise Ship

Sep 4th, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.52 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.         String destination = scanner.nextLine(),
  7.                 cabinType = scanner.nextLine();
  8.         int overnights = Integer.parseInt(scanner.nextLine());
  9.         double dayPrice;
  10.  
  11.         if (destination.equals("Mediterranean")) {
  12.             if (cabinType.equals("standard cabin")) {
  13.                 dayPrice = 27.50;
  14.             } else if (cabinType.equals("cabin with balcony")) {
  15.                 dayPrice = 30.20;
  16.             } else {
  17.                 dayPrice = 40.50;
  18.             }
  19.         } else if (destination.equals("Adriatic")) {
  20.             if (cabinType.equals("standard cabin")) {
  21.                 dayPrice = 22.99;
  22.             } else if (cabinType.equals("cabin with balcony")) {
  23.                 dayPrice = 25.00;
  24.             } else {
  25.                 dayPrice = 34.99;
  26.             }
  27.         } else {
  28.             if (cabinType.equals("standard cabin")) {
  29.                 dayPrice = 23.00;
  30.             } else if (cabinType.equals("cabin with balcony")) {
  31.                 dayPrice = 26.60;
  32.             } else {
  33.                 dayPrice = 39.80;
  34.             }
  35.         }
  36.  
  37.         double totalSum = dayPrice * 4 * overnights;
  38.         if (overnights > 7) {
  39.             totalSum *= 0.75;
  40.         }
  41.  
  42.         System.out.printf("Annie's holiday in the %s sea costs %.2f lv.\n", destination, totalSum);
  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.         String destination = scanner.nextLine(),
  54.                 cabinType = scanner.nextLine();
  55.         int overnights = Integer.parseInt(scanner.nextLine());
  56.  
  57.         double dayPrice = destination.equals("Mediterranean")
  58.                         ? (cabinType.equals("standard cabin") ? 27.50 : cabinType.equals("cabin with balcony") ? 30.20 : 40.50)
  59.                         : destination.equals("Adriatic")
  60.                         ? (cabinType.equals("standard cabin") ? 22.99 : cabinType.equals("cabin with balcony") ? 25.00 : 34.99)
  61.                         : (cabinType.equals("standard cabin") ? 23.00 : cabinType.equals("cabin with balcony") ? 26.60 : 39.80);
  62.  
  63.         double totalSum = dayPrice * 4 * overnights * (overnights > 7 ? 0.75 : 1);
  64.  
  65.         System.out.printf("Annie's holiday in the %s sea costs %.2f lv.\n", destination, totalSum);
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement