Advertisement
Valantina

CruiseShip/Ex/27.07.2019/Java

Jul 29th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.12 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P03_CruiseShip {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         String cruise = scan.nextLine();
  8.         String cabinType = scan.nextLine();
  9.         int nights = Integer.parseInt(scan.nextLine());
  10.  
  11.         double price = 0;
  12.  
  13.         switch (cruise) {
  14.             case "Mediterranean":
  15.                 if (cabinType.equals("standard cabin")) {
  16.                     price = nights * 4 * 27.50;
  17.                 } else if (cabinType.equals("cabin with balcony")) {
  18.                     price = nights * 4 * 30.20;
  19.                 } else if (cabinType.equals("apartment")) {
  20.                     price = nights * 4 * 40.50;
  21.                 } else {
  22.                     System.out.println("Invalid cabin type!");
  23.                 }
  24.                 break;
  25.             case "Adriatic":
  26.                 if (cabinType.equals("standard cabin")) {
  27.                     price = nights * 4 * 22.99;
  28.                 } else if (cabinType.equals("cabin with balcony")) {
  29.                     price = nights * 4 * 25.00;
  30.                 } else if (cabinType.equals("apartment")) {
  31.                     price = nights * 4 * 34.99;
  32.                 } else {
  33.                     System.out.println("Invalid cabin type!");
  34.                 }
  35.                 break;
  36.             case "Aegean":
  37.                 if (cabinType.equals("standard cabin")) {
  38.                     price = nights * 4 * 23.00;
  39.                 } else if (cabinType.equals("cabin with balcony")) {
  40.                     price = nights * 4 * 26.60;
  41.                 } else if (cabinType.equals("apartment")) {
  42.                     price = nights * 4 * 39.80;
  43.                 } else {
  44.                     System.out.println("Invalid cabin type!");
  45.                 }
  46.                 break;
  47.             default:
  48.                 System.out.println("Invalid cruise!");
  49.                 break;
  50.         }
  51.  
  52.         if (nights > 7) {
  53.             price = 0.75 * price;
  54.         }
  55.  
  56.         System.out.println(String.format("Annie's holiday in the %s sea costs %.2f lv.", cruise, price));
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement