Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 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. String fruit = scanner.nextLine();
  7. String day = scanner.nextLine();
  8. double quantity = Double.parseDouble(scanner.nextLine());
  9. double price = 0;
  10. if (day.equals("Monday") || day.equals("Tuesday") || day.equals("Wednesday") || day.equals("Thursday")
  11. || day.equals("Friday")) {
  12. switch (fruit) {
  13. case "banana":
  14. price = quantity * 2.5;
  15. break;
  16. case "apple":
  17. price = quantity * 1.20;
  18. break;
  19. case "orange":
  20. price = quantity * 0.85;
  21. break;
  22. case "grapefruit":
  23. price = quantity * 1.45;
  24. break;
  25. case "kiwi":
  26. price = quantity * 2.70;
  27. break;
  28. case "pineaplle":
  29. price = quantity * 1.50;
  30. break;
  31. case "grape":
  32. price = quantity * 3.85;
  33. break;
  34. default:
  35. }
  36.  
  37. }else if (day.equals("Saturday") || day.equals("Sunday")){
  38. switch (fruit) {
  39. case "banana":
  40. price = quantity * 2.70;
  41. break;
  42. case "apple":
  43. price = quantity * 1.25;
  44. break;
  45. case "orange":
  46. price = quantity * 0.90;
  47. break;
  48. case "grapefruit":
  49. price = quantity * 1.60;
  50. break;
  51. case "kiwi":
  52. price = quantity * 3.00;
  53. break;
  54. case "pineapple":
  55. price = quantity * 5.60;
  56. break;
  57. case "grapes":
  58. price = quantity * 4.20;
  59. break;
  60. default:
  61. }
  62.  
  63. }
  64. if (price > 0){
  65. System.out.printf("%.2f", price );
  66. }else {
  67. System.out.print("error");
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement