Advertisement
GabrielHr00

09. Ski Trip

May 28th, 2023
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. package S3_ConditionalStatementsAdvanced;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class SkiTrip {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int days = Integer.parseInt(scanner.nextLine());
  9.         String roomType = scanner.nextLine();
  10.         String grade = scanner.nextLine();
  11.  
  12.         int nights = days - 1;
  13.         double finalPrice = 0.0;
  14.  
  15.         if(roomType.equals("room for one person")) {
  16.             finalPrice = 18.0 * nights;
  17.         }
  18.         else if(roomType.equals("apartment")) {
  19.             finalPrice = 25.0 * nights;
  20.  
  21.             if (days < 10) {
  22.                 finalPrice = finalPrice * 0.70;
  23.             } else if (days >= 10 && days <= 15) {
  24.                 finalPrice = finalPrice * 0.65;
  25.             } else if (days > 15) {
  26.                 finalPrice = finalPrice * 0.50;
  27.             }
  28.         }
  29.         else if(roomType.equals("president apartment")) {
  30.             finalPrice = 35.0 * nights;
  31.  
  32.             if (days < 10) {
  33.                 finalPrice = finalPrice * 0.90;
  34.             } else if (days >= 10 && days <= 15) {
  35.                 finalPrice = finalPrice * 0.85;
  36.             } else if (days > 15) {
  37.                 finalPrice = finalPrice * 0.80;
  38.             }
  39.         }
  40.  
  41.         switch(grade) {
  42.             case "positive":
  43.                 finalPrice = finalPrice + (finalPrice * 0.25);
  44.                 break;
  45.             case "negative":
  46.                 finalPrice = finalPrice - (finalPrice * 0.10);
  47.                 break;
  48.         }
  49.  
  50.         System.out.printf("%.2f", finalPrice);
  51.     }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement