Advertisement
uktcar

03.2.04FishingBoat

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