Advertisement
Lyubohd

03. Travel Agency

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