Advertisement
Valantina

TravelAgency/Ex/Java

Jul 9th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.39 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P03_TravelAgency {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         String town = scan.nextLine();
  8.         String pack = scan.nextLine();
  9.         boolean hasVIP = scan.nextLine().equals("yes");
  10.         int days = Integer.parseInt(scan.nextLine());
  11.         boolean isValid = false;
  12.  
  13.         double price = 0.0;
  14.  
  15.         if (days > 7) {
  16.             days--;
  17.         }
  18.  
  19.         switch (town) {
  20.             case "Bansko":
  21.             case "Borovets":
  22.                 if (hasVIP) {
  23.                     if ("noEquipment".equals(pack)) {
  24.                         price = 80 * 0.95;
  25.                     } else if ("withEquipment".equals(pack)) {
  26.                         price = 100 * 0.9;
  27.                     } else {
  28.                         isValid = true;
  29.                     }
  30.                 } else {
  31.                     if ("noEquipment".equals(pack)) {
  32.                         price = 80;
  33.                     } else if ("withEquipment".equals(pack)) {
  34.                         price = 100;
  35.                     } else {
  36.                         isValid = true;
  37.                     }
  38.                 }
  39.                 break;
  40.             case "Varna":
  41.             case "Burgas":
  42.                 if (hasVIP) {
  43.                     if ("withBreakfast".equals(pack)) {
  44.                         price = 130 * 0.88;
  45.                     } else if ("noBreakfast".equals(pack)) {
  46.                         price = 100 * 0.92;
  47.                     } else {
  48.                         isValid = true;
  49.                     }
  50.                 } else {
  51.                     if ("withBreakfast".equals(pack)) {
  52.                         price = 130;
  53.                     } else if ("noBreakfast".equals(pack)) {
  54.                         price = 100;
  55.                     } else {
  56.                         isValid = true;
  57.                     }
  58.                 }
  59.                 break;
  60.             default:
  61.                 isValid = true;
  62.                 break;
  63.         }
  64.         if (isValid) {
  65.             System.out.println("Invalid input!");
  66.         } else if (days < 1) {
  67.             System.out.println("Days must be positive number!");
  68.         } else {
  69.             double finalPrice = days * price;
  70.             System.out.println(String.format("The price is %.2flv! Have a nice time!", finalPrice));
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement