Advertisement
veronikaaa86

04. Fishing Boat

Jan 23rd, 2022
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. package advancedConditionalStatements;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P04Fishingoat {
  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. //"Spring", "Summer", "Autumn", "Winter"
  14. double boatPrice = 0;
  15. switch (season) {
  16. case "Spring":
  17. boatPrice = 3000;
  18. break;
  19. case "Summer":
  20. case "Autumn":
  21. boatPrice = 4200;
  22. break;
  23. case "Winter":
  24. boatPrice = 2600;
  25. break;
  26. }
  27.  
  28. if (people <= 6) {
  29. boatPrice = boatPrice * 0.90;
  30. } else if (people <= 11) {
  31. boatPrice = boatPrice * 0.85;
  32. } else {
  33. boatPrice = boatPrice * 0.75;
  34. }
  35.  
  36. if (people % 2 == 0 && !season.equals("Autumn")) {
  37. boatPrice = boatPrice * 0.95;
  38. }
  39.  
  40. double diff = Math.abs(budget - boatPrice);
  41. if (budget >= boatPrice) {
  42. System.out.printf("Yes! You have %.2f leva left.", diff);
  43. } else {
  44. System.out.printf("Not enough money! You need %.2f leva.", diff);
  45. }
  46. }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement