myrdok123

07. Hotel Room

Jan 21st, 2024
1,016
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.31 KB | None | 0 0
  1. package W03ConditionalStatementsAdvanced.Exercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P07HotelRoom {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String month = scanner.nextLine();
  10.         int countNights = Integer.parseInt(scanner.nextLine());
  11.  
  12.         double priceForTheApartment = 0;
  13.         double priceForTheStudio = 0;
  14.  
  15.         switch (month){
  16.  
  17.             case "May":
  18.             case "October":
  19.                 //Пресмятаме цената за студио и апартамен
  20.                 priceForTheApartment = countNights * 65;
  21.                 priceForTheStudio = countNights * 50;
  22.  
  23.                 //Проверяваме дали имаме отстъпка спрямо броя нощувки
  24.                 if(countNights > 14){
  25.                     priceForTheStudio = priceForTheStudio * 0.70;
  26.                     priceForTheApartment = priceForTheApartment * 0.90;
  27.                 } else if (countNights > 7) {
  28.                     priceForTheStudio = priceForTheStudio * 0.95;
  29.  
  30.  
  31.                 }
  32.                 break;
  33.  
  34.             case "June":
  35.             case "September":
  36.                 //Пресмятаме цената за студио и апартамен
  37.                 priceForTheApartment = countNights * 68.70;
  38.                 priceForTheStudio = countNights * 75.20;
  39.  
  40.                 //Проверяваме дали нощувките са повече от 14 -> правим 20% отстъпка
  41.                 if(countNights > 14){
  42.  
  43.                     priceForTheStudio = priceForTheStudio * 0.80;
  44.                     priceForTheApartment = priceForTheApartment * 0.90;
  45.                 }
  46.  
  47.                 break;
  48.  
  49.             case "July":
  50.             case "August":
  51.                 //Пресмятаме цената за студио и апартамен
  52.                 priceForTheApartment = countNights * 77;
  53.                 priceForTheStudio = countNights * 76;
  54.  
  55.                 if(countNights > 14){
  56.                     priceForTheApartment = priceForTheApartment * 0.90;
  57.                 }
  58.  
  59.  
  60.                 break;
  61.         }
  62.  
  63.         System.out.printf("Apartment: %.2f lv.%n", priceForTheApartment);
  64.         System.out.printf("Studio: %.2f lv.", priceForTheStudio);
  65.     }
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment