Advertisement
Spocoman

04. Fishing Boat

Aug 26th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FishingBoat {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int budget = Integer.parseInt(scanner.nextLine());
  7.         String season = scanner.nextLine();
  8.         int people = Integer.parseInt(scanner.nextLine());
  9.  
  10.         double sum = switch (season) {
  11.             case "Spring" -> 3000;
  12.             case "Summer", "Autumn" -> 4200;
  13.             case "Winter" -> 2600;
  14.             default -> 0;
  15.         };
  16.  
  17.         if (people <= 6) {
  18.             sum *= 0.9;
  19.         } else if (people <= 11) {
  20.             sum *= 0.85;
  21.         } else {
  22.             sum *= 0.75;
  23.         }
  24.  
  25.         if (people % 2 == 0 && !season.equals("Autumn")) {
  26.             sum *= 0.95;
  27.         }
  28.  
  29.         if (sum <= budget) {
  30.             System.out.printf("Yes! You have %.2f leva left.", budget - sum);
  31.         } else {
  32.             System.out.printf("Not enough money! You need %.2f leva.", sum - budget);
  33.         }
  34.     }
  35. }
  36.  
  37. ИЛИ:
  38.  
  39. import java.util.Scanner;
  40.  
  41. public class FishingBoat {
  42.     public static void main(String[] args) {
  43.         Scanner scanner = new Scanner(System.in);
  44.         double budget = Double.parseDouble(scanner.nextLine());
  45.         String season = scanner.nextLine();
  46.         int people = Integer.parseInt(scanner.nextLine());
  47.  
  48.         budget -= (season.equals("Spring") ? 3000 : season.equals("Winter") ? 2600 : 4200)
  49.                 * (people <= 6 ? 0.9 : people > 11 ? 0.75 : 0.85)
  50.                 * (people % 2 == 0 && !season.equals("Autumn") ? 0.95 : 1);
  51.  
  52.         if (budget >= 0) {
  53.             System.out.printf("Yes! You have %.2f leva left.", budget);
  54.         } else {
  55.             System.out.printf("Not enough money! You need %.2f leva.", Math.abs(budget));
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement