myrdok123

07. Hotel Room

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