galinyotsev123

ProgBasics04Nested-Statements-Y06fishingBoat

Jan 6th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1.  
  2.  
  3. import java.io.BufferedReader;
  4. import java.util.Scanner;
  5.  
  6. public class Y06fishingBoat {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9.  
  10. int budget = Integer.parseInt(scanner.nextLine());
  11. String season = scanner.nextLine();
  12. int countFisherman = Integer.parseInt(scanner.nextLine());
  13.  
  14. int priceSpring = 3000;
  15. int priceSummerAutumn = 4200;
  16. int priceWinter = 2600;
  17.  
  18. double priceForSeason = 0;
  19.  
  20. switch (season.toLowerCase()) {
  21. case "spring":
  22. priceForSeason = priceSpring;
  23. break;
  24. case "summer":
  25. case "autumn":
  26. priceForSeason = priceSummerAutumn;
  27. break;
  28. case "winter":
  29. priceForSeason = priceWinter;
  30. break;
  31. }
  32.  
  33. int discount = 0;
  34. if (countFisherman <= 6) {
  35. discount = 10;
  36. } else if (countFisherman <= 11) {
  37. discount = 15;
  38. } else {
  39. discount = 25;
  40. }
  41.  
  42. double priceWithDiscount =
  43. priceForSeason - priceForSeason * discount / 100.0;
  44.  
  45. int additionalDiscount = 0;
  46. if (countFisherman % 2 == 0 && !"autumn".equalsIgnoreCase(season)) {
  47. additionalDiscount = 5;
  48. }
  49.  
  50. double finalPriceWithDiscount =
  51. priceWithDiscount - priceWithDiscount * additionalDiscount / 100.0;
  52.  
  53. double diff = budget - finalPriceWithDiscount;
  54. if (budget >= finalPriceWithDiscount) {
  55. System.out.printf("Yes! You have %.2f leva left.", diff);
  56. } else {
  57. System.out.printf("Not enough money! You need %.2f leva.", Math.abs(diff));
  58. }
  59.  
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment