Advertisement
desislava_topuzakova

10. Ski Trip

May 2nd, 2020
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.44 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SkiTrip_10 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         //1. крайна цена = бр. нощувки * цена за 1 нощувка
  7.         //бр.нощувки = дни - 1
  8.         //цена за 1 нощувка -> зависи от типа на стаята
  9.         //2. намалението
  10.         //3. оценка
  11.  
  12.         int days = Integer.parseInt(scanner.nextLine());
  13.         String roomType = scanner.nextLine(); // "room  for  one  person", "apartment" или "president  apartment"
  14.         String grade = scanner.nextLine(); // "positive"  или "negative"
  15.  
  16.         int nights = days - 1; //нощувки
  17.         double pricePerNight = 0;
  18.         //проверка за стаята
  19.         switch (roomType) {
  20.             case "room for one person":
  21.                 pricePerNight = 18;
  22.                 break;
  23.             case "apartment":
  24.                 pricePerNight = 25;
  25.                 break;
  26.             case "president apartment":
  27.                 pricePerNight = 35;
  28.                 break;
  29.  
  30.         }
  31.  
  32.         double totalPrice = nights * pricePerNight;
  33.  
  34.         if (roomType.equals("apartment")) {
  35.             if (days < 10) {
  36.                 //-30%
  37.                 totalPrice = totalPrice - 0.3 * totalPrice; //0.7 * totalPrice;
  38.             } else if (days >= 10 && days <= 15) {
  39.                 //-35%
  40.                 totalPrice = totalPrice - 0.35 * totalPrice; //0.65 * totalPrice
  41.             } else if (days > 15) {
  42.                 //-50% -> 0.5
  43.                 totalPrice = totalPrice - 0.5 * totalPrice;
  44.             }
  45.         } else if (roomType.equals("president apartment")) {
  46.             if (days < 10) {
  47.                 //-10%
  48.                 totalPrice = totalPrice - 0.1 * totalPrice; //0.9 * totalPrice;
  49.             } else if (days >= 10 && days <= 15) {
  50.                 //-15%
  51.                 totalPrice = totalPrice - 0.15 * totalPrice; //0.85 * totalPrice
  52.             } else if (days > 15) {
  53.                 //-20% -> 0.2
  54.                 totalPrice = totalPrice - 0.2 * totalPrice;
  55.             }
  56.         }
  57.  
  58.         if (grade.equals("positive")){
  59.             totalPrice = totalPrice + 0.25 * totalPrice; //1.25
  60.         } else if (grade.equals("negative")){
  61.             totalPrice = totalPrice - 0.10 * totalPrice;
  62.         }
  63.  
  64.         System.out.printf("%.2f", totalPrice);
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement