Advertisement
veronikaaa86

04. Fishing Boat

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