Advertisement
Spocoman

05. Journey

Aug 26th, 2024
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.99 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Journey {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         double budget = Double.parseDouble(scanner.nextLine());
  7.         String season = scanner.nextLine();
  8.  
  9.         String place = "";
  10.         String region = "";
  11.         double sum = 0;
  12.  
  13.         switch (season) {
  14.             case "summer":
  15.                 place = "Camp";
  16.                 if (budget <= 100) {
  17.                     sum = 0.3 * budget;
  18.                 } else if (budget > 100 && budget <= 1000) {
  19.                     sum = 0.4 * budget;
  20.                 }
  21.                 break;
  22.             case "winter":
  23.                 place = "Hotel";
  24.                 if (budget <= 100) {
  25.                     sum = 0.7 * budget;
  26.                 } else if (budget > 100 && budget <= 1000) {
  27.                     sum = 0.8 * budget;
  28.                 }
  29.                 break;
  30.         }
  31.  
  32.         if (budget <= 100) {
  33.             region = "Bulgaria";
  34.         } else if (budget > 100 && budget <= 1000) {
  35.             region = "Balkans";
  36.         } else {
  37.             place = "Hotel";
  38.             region = "Europe";
  39.             sum = 0.9 * budget;
  40.         }
  41.  
  42.         System.out.printf("Somewhere in %s\n%s - %.2f", region, place, sum);
  43.     }
  44. }
  45.  
  46. ИЛИ:
  47.  
  48. import java.util.Scanner;
  49.  
  50. public class Journey {
  51.     public static void main(String[] args) {
  52.         Scanner scanner = new Scanner(System.in);
  53.         double budget = Double.parseDouble(scanner.nextLine());
  54.         String season = scanner.nextLine();
  55.  
  56.         String place = season.equals("summer") && budget <= 1000 ? "Camp" : "Hotel";
  57.         String region = budget <= 100 ? "Bulgaria" : budget > 1000 ? "Europe" : "Balkans";
  58.  
  59.         budget *= budget <= 100 ? (season.equals("summer") ? 0.3 : 0.7)
  60.                 : budget > 100 && budget <= 1000 ? (season.equals("summer") ? 0.4 : 0.8) : 0.9;
  61.  
  62.         System.out.printf("Somewhere in %s\n%s - %.2f", region, place, budget);
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement