Advertisement
damesova

Hotel Room - Java

Nov 23rd, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. package NestedIfExcercises;
  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.  
  12. double priceApartment = 0;
  13. double priceStudio = 0;
  14.  
  15. if (month.equals("May") || month.equals("October")) {
  16. if (nights > 7 && nights <= 14) {
  17. priceStudio = 50 - 0.05 * 50;
  18. priceApartment = 65;
  19. } else if (nights > 14) {
  20. priceStudio = 50 - 0.3 * 50;
  21. priceApartment = 65 - 0.1 * 65;
  22. } else {
  23. priceStudio = 50;
  24. priceApartment = 65;
  25. }
  26. } else if (month.equals("June") || month.equals("September")) {
  27. if (nights > 14) {
  28. priceStudio = 75.20 - 0.20 * 75.20;
  29. priceApartment = 68.70 - 0.1 * 68.70;
  30. } else {
  31. priceStudio = 75.20;
  32. priceApartment = 68.70;
  33. }
  34.  
  35.  
  36. } else if (month.equals("July") || month.equals("August")) {
  37. if (nights > 14) {
  38. priceApartment = 77 - 0.1 * 77;
  39. } else {
  40.  
  41. priceApartment = 77;
  42. }
  43. priceStudio = 76;
  44. }
  45.  
  46. double totalPriceForStudio = nights * priceStudio;
  47. double totalPriceForApartment = nights * priceApartment;
  48.  
  49. System.out.printf("Apartment: %.2f lv.%n", totalPriceForApartment);
  50. System.out.printf("Studio: %.2f lv.", totalPriceForStudio);
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement