Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FruitShop {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. // banana / apple / orange / grapefruit / kiwi / pineapple / grapes
  8.  
  9. String fruit = (scanner.nextLine());
  10. String dayOfWeek = (scanner.nextLine());
  11. double quantity = Double.parseDouble(scanner.nextLine());
  12. double totalPrice = 0;
  13. switch (dayOfWeek) {
  14. case "Monday":
  15. case "Tuesday":
  16. case "Wednesday":
  17. case "Thursday":
  18. case "Friday":
  19. switch (fruit) {
  20. case "banana":
  21. totalPrice = quantity * 2.50;
  22. System.out.printf("%.2f", totalPrice);
  23. break;
  24. case "apple":
  25. totalPrice = quantity * 1.20;
  26. System.out.printf("%.2f", totalPrice);
  27. break;
  28. case "orange":
  29. totalPrice = quantity * 0.85;
  30. System.out.printf("%.2f", totalPrice);
  31. break;
  32. case "grapefruit":
  33. totalPrice = quantity * 1.45;
  34. System.out.printf("%.2f", totalPrice);
  35. break;
  36. case "kiwi":
  37. totalPrice = quantity * 2.70;
  38. System.out.printf("%.2f", totalPrice);
  39. break;
  40. case "pineapple":
  41. totalPrice = quantity * 5.50;
  42. System.out.printf("%.2f", totalPrice);
  43. break;
  44. case "grapes":
  45. totalPrice = quantity * 3.85;
  46. System.out.printf("%.2f", totalPrice);
  47. break;
  48. default: System.out.printf("error");
  49. break;
  50. }
  51.  
  52. break;
  53. case "Saturday":
  54. case "Sunday":
  55. switch (fruit) {
  56. case "banana":
  57. totalPrice = quantity * 2.70;
  58. System.out.printf("%.2f", totalPrice);
  59. break;
  60. case "apple":
  61. totalPrice = quantity * 1.25;
  62. System.out.printf("%.2f", totalPrice);
  63. break;
  64. case "orange":
  65. totalPrice = quantity * 0.90;
  66. System.out.printf("%.2f", totalPrice);
  67. break;
  68. case "grapefruit":
  69. totalPrice = quantity * 1.60;
  70. System.out.printf("%.2f", totalPrice);
  71. break;
  72. case "kiwi":
  73. totalPrice = quantity * 3.00;
  74. System.out.printf("%.2f", totalPrice);
  75. break;
  76. case "pineapple":
  77. totalPrice = quantity * 5.60;
  78. System.out.printf("%.2f", totalPrice);
  79. break;
  80. case "grapes":
  81. totalPrice = quantity * 4.20;
  82. System.out.printf("%.2f", totalPrice);
  83. break;
  84. default: System.out.printf("error");
  85. break;
  86. }
  87.  
  88. break;
  89.  
  90. default:
  91. System.out.println("error");
  92. break;
  93. }
  94.  
  95. }
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement