skipter

Hotel Room - Logical Operators / Java Basic

May 3rd, 2017
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. package com.company;
  2. import java.util.Scanner;
  3. public class Main {
  4.     public static void main(String[] args) {
  5.  
  6.         Scanner input = new Scanner(System.in);
  7.  
  8.         String month = input.nextLine();
  9.         int nights = Integer.parseInt(input.nextLine());
  10.  
  11.         double studio = 0;
  12.         double flat = 0;
  13.         double totalPriceStudio = 0;
  14.         double totalPriceFlat = 0;
  15.  
  16.         if (month.equals("May") || month.equals("October")) {
  17.             studio = 50;
  18.             flat = 65;
  19.         } else if (month.equals("June") || month.equals("September")) {
  20.             studio = 75.20;
  21.             flat = 68.70;
  22.         } else if (month.equals("July") || (month.equals("August"))) {
  23.             studio = 76;
  24.             flat = 77;
  25.         }
  26.  
  27.         totalPriceStudio = nights * studio;
  28.         totalPriceFlat = nights * flat;
  29.  
  30.         if ((nights > 7 && nights < 14) && (month.equals("May") || month.equals("October"))) {
  31.             totalPriceStudio -= totalPriceStudio * 0.05;
  32.         } else if ((nights > 14) && (month.equals("May") || month.equals("October"))) {
  33.             totalPriceStudio -= totalPriceStudio * 0.30;
  34.         } else if ((nights > 14) && (month.equals("June") || month.equals("September"))) {
  35.             totalPriceStudio -= totalPriceStudio * 0.20;
  36.         }
  37.         if (nights > 14 & (month.equals("July") || (month.equals("August") || (month.equals("May") || month.equals("October") || (month.equals("June") || month.equals("September")))))) {
  38.             totalPriceFlat -= totalPriceFlat * 0.10;
  39.         }
  40.         System.out.printf("Apartment: %.2f lv.%n", totalPriceFlat);
  41.         System.out.printf("Studio: %.2f lv.", totalPriceStudio);
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment