Advertisement
mimisimi

Лодка за риболов

Nov 24th, 2018
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 KB | None | 0 0
  1. package NestedCondStat.Exercises;
  2.  
  3. import java.util.Objects;
  4. import java.util.Scanner;
  5.  
  6. public class Fishers {
  7.     public static void main(String[] args) {
  8.         try (Scanner scanner = new Scanner(System.in)) {
  9.             int budget = Integer.parseInt(scanner.nextLine());
  10.             String season = scanner.nextLine();
  11.             int fishers = Integer.parseInt(scanner.nextLine());
  12.             double rent = 0.0;
  13.  
  14.             switch (season) {
  15.                 case "Spring":
  16.                     rent = 3000;
  17.                     break;
  18.                 case "Summer":
  19.                     rent = 4200;
  20.                     break;
  21.                 case "Autumn":
  22.                     rent = 4200;
  23.                     break;
  24.                 case "Winter":
  25.                     rent = 2600;
  26.                     break;
  27.             }
  28.             double discount = 0.0;
  29.  
  30.             if (fishers <= 6) {
  31.                 discount = 0.1*rent;
  32.             } else if (fishers >= 7 && fishers <= 11) {
  33.                 discount = 0.15*rent;
  34.             } else if (fishers >= 12) {
  35.                 discount = 0.25*rent;
  36.             }
  37.  
  38.             double discount2 = 0.0;
  39.  
  40.             if (fishers % 2 == 0 && !Objects.equals(season, "Autumn"))
  41.             { discount2 = 0.05*(rent-discount);
  42.             }
  43.  
  44.             double total = rent - (discount + discount2);
  45.             double left = budget-total;
  46.             if(budget>=total){
  47.                 System.out.printf("Yes! You have %.2f leva left.", left);
  48.  
  49.             }else{
  50.                 System.out.printf("Not enough money! You need %.2f leva.", total-budget);
  51.             }
  52.  
  53.             }
  54.             }
  55.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement