Advertisement
Spocoman

09. Ski Trip

Aug 26th, 2024 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.37 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SkiTrip {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int nights = Integer.parseInt(scanner.nextLine()) - 1;
  7.         String room = scanner.nextLine();
  8.         String rating = scanner.nextLine();
  9.  
  10.         int roomPricePerNight = 18,
  11.                 apartmentPricePerNight = 25,
  12.                     presidentApartmentPerNight = 35;
  13.  
  14.         double totalSum = 0;
  15.  
  16.         if (room.equals("room for one person")) {
  17.             totalSum = roomPricePerNight * nights;
  18.         } else if (room.equals("apartment")) {
  19.             totalSum = apartmentPricePerNight * nights;
  20.  
  21.             if (nights < 10) {
  22.                 totalSum *= 0.70;
  23.             } else if (nights < 15) {
  24.                 totalSum *= 0.65;
  25.             } else {
  26.                 totalSum *= 0.50;
  27.             }
  28.         } else if (room.equals("president apartment")) {
  29.             totalSum = presidentApartmentPerNight * nights;
  30.  
  31.             if (nights < 10) {
  32.                 totalSum *= 0.90;
  33.             } else if (nights < 15) {
  34.                 totalSum *= 0.85;
  35.             } else {
  36.                 totalSum *= 0.80;
  37.             }
  38.         }
  39.  
  40.         if (rating.equals("positive")) {
  41.             totalSum *= 1.25;
  42.         } else if (rating.equals("negative")) {
  43.             totalSum *= 0.90;
  44.         }
  45.  
  46.         System.out.printf("%.2f\n", totalSum);
  47.     }
  48. }
  49.  
  50. ИЛИ:
  51.  
  52. import java.util.Scanner;
  53.  
  54. public class SkiTrip {
  55.     public static void main(String[] args) {
  56.         Scanner scanner = new Scanner(System.in);
  57.         int nights = Integer.parseInt(scanner.nextLine()) - 1;
  58.         String room = scanner.nextLine();
  59.         String rating = scanner.nextLine();
  60.  
  61.         int roomPricePerNight = 18,
  62.                 apartmentPricePerNight = 25,
  63.                 presidentApartmentPerNight = 35;
  64.  
  65.         double totalSum = nights * switch (room) {
  66.             case "room for one person" -> roomPricePerNight;
  67.             case "apartment" -> apartmentPricePerNight * (nights < 10 ? 0.70 : nights < 15 ? 0.65 : 0.50);
  68.             case "president apartment" -> presidentApartmentPerNight * (nights < 10 ? 0.90 : nights < 15 ? 0.85 : 0.80);
  69.             default -> 0;
  70.         };
  71.  
  72.         totalSum *= rating.equals("positive") ? 1.25 : 0.90;
  73.  
  74.         System.out.printf("%.2f\n", totalSum);
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement