Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.22 KB | None | 0 0
  1. package NestedConditionalStatements;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class HotelRoom {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String month = scanner.nextLine();
  10.         int nights = Integer.parseInt(scanner.nextLine());
  11.         //•   За студио, при повече от 7 нощувки през май и октомври : 5% намаление.
  12.         //•   За студио, при повече от 14 нощувки през май и октомври : 30% намаление.
  13.         //•   За студио, при повече от 14 нощувки през юни и септември: 20% намаление.
  14.         //•   За апартамент, при повече от 14 нощувки, без значение от месеца : 10% намаление.
  15.  
  16.         double priceApartment = 0;
  17.         double priceStudio = 0;
  18.  
  19.         if (month.equals("May") || month.equals("October")) {
  20.             if (nights > 7 && nights <= 14) {
  21.                 priceStudio = 50 - 0.05 * 50;
  22.                 priceApartment = 65;
  23.             } else if (nights > 14) {
  24.                 priceStudio = 50 - 0.3 * 50;
  25.                 priceApartment = 65 - 0.1 * 65;
  26.             } else {
  27.                 priceStudio = 50;
  28.                 priceApartment = 65;
  29.             }
  30.         } else if (month.equals("June") || month.equals("September")) {
  31.             if (nights > 14) {
  32.                 priceStudio = 75.20 - 0.20 * 75.20;
  33.                 priceApartment = 68.70 - 0.1 * 68.70;
  34.             } else {
  35.                 priceStudio = 75.20;
  36.                 priceApartment = 68.70;
  37.             }
  38.  
  39.  
  40.         } else if (month.equals("July") || month.equals("August")) {
  41.             if (nights > 14) {
  42.                 priceApartment = 77 - 0.1 * 77;
  43.             } else {
  44.  
  45.                 priceApartment = 77;
  46.             }
  47.             priceStudio = 76;
  48.         }
  49.  
  50.         double totalPriceForStudio = nights * priceStudio;
  51.         double totalPriceForApartment = nights * priceApartment;
  52.  
  53.         System.out.printf("Apartment: %.2f lv.%n", totalPriceForApartment);
  54.         System.out.printf("Studio: %.2f lv.", totalPriceForStudio);
  55.  
  56.  
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement