Advertisement
CR7CR7

hotelRoom

Apr 15th, 2023
915
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.71 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class HotelRoom {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String month = scanner.nextLine();
  7.         int daysCount = Integer.parseInt(scanner.nextLine());
  8.         double studioPrice = 0;
  9.         double apartmentPrice = 0;
  10.        
  11.         switch (month) {
  12.             case "May":
  13.             case "October":
  14.                 studioPrice = 50;
  15.                 apartmentPrice = 65;
  16.                 if (daysCount > 14) {
  17.                     studioPrice *= 0.7; // 30% discount
  18.                     apartmentPrice *= 0.9; // 10% discount
  19.                 } else if (daysCount > 7) {
  20.                     studioPrice *= 0.95; // 5% discount
  21.                 }
  22.                 break;
  23.             case "June":
  24.             case "September":
  25.                 studioPrice = 75.20;
  26.                 apartmentPrice = 68.70;
  27.                 if (daysCount > 14) {
  28.                     studioPrice *= 0.8; // 20% discount
  29.                     apartmentPrice *= 0.9; // 10% discount
  30.                 }
  31.                 break;
  32.             case "July":
  33.             case "August":
  34.                 studioPrice = 76;
  35.                 apartmentPrice = 77;
  36.                 if (daysCount > 14) {
  37.                     apartmentPrice *= 0.9; // 10% discount
  38.                 }
  39.                 break;
  40.         }
  41.  
  42.         // Calculate the final prices for studio and apartment
  43.         studioPrice *= daysCount;
  44.         apartmentPrice *= daysCount;
  45.  
  46.         // Print the output formatted to two decimal places
  47.         System.out.printf("Apartment: %.2f lv.%n", apartmentPrice);
  48.         System.out.printf("Studio: %.2f lv.%n", studioPrice);
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement