Advertisement
Kancho

Fruit_Vegetable_Shop

Jan 27th, 2019
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Fruit_Vegetable_Shop {
  4. public static void main(String[] args) {
  5. Scanner keyboard = new Scanner(System.in);
  6. System.out.print("Enter day of the week: ");
  7. String day = keyboard.next();
  8. System.out.print("Enter commodity: ");
  9. String commodity = keyboard.next();
  10. System.out.print("Enter quantity: ");
  11. double quantity = keyboard.nextDouble();
  12. //ΠΏΠ»ΠΎΠ΄ banana apple orange grapefruit kiwi pineapple grapes
  13. // (Monday / Tuesday / Wednesday / Thursday / Friday
  14. boolean isWorkDay = "Monday".equalsIgnoreCase(day) ||
  15. "Tuesday".equalsIgnoreCase(day) ||
  16. "Wednesday".equalsIgnoreCase(day) ||
  17. "Thursday".equalsIgnoreCase(day) ||
  18. "Friday".equalsIgnoreCase(day);
  19. boolean weekEnd = "Saturday".equalsIgnoreCase(day) || "Sunday".equalsIgnoreCase(day);
  20.  
  21. switch (commodity) {
  22. case "banana":
  23. if (isWorkDay) {
  24. System.out.printf("%.2f", quantity *2.50);
  25. } else if (weekEnd) {
  26. System.out.printf("%.2f", quantity * 2.70);
  27. }
  28. break;
  29. case "apple":
  30. if (isWorkDay) {
  31. System.out.printf("%.2f", quantity * 1.20);
  32. } else if (weekEnd) {
  33. System.out.printf("%.2f", quantity * 1,30);
  34. }
  35. break;
  36. case "orange":
  37. if (isWorkDay) {
  38. System.out.printf("%.2f", quantity * 0.85);
  39. } else if (weekEnd) {
  40. System.out.printf("%.2f", quantity * 0.90);
  41. }
  42. break;
  43. case "grapefruit":
  44. if (isWorkDay) {
  45. System.out.printf("%.2f", quantity * 1.45);
  46. } else if (weekEnd) {
  47. System.out.printf("%.2f",quantity * 1.60);
  48. }
  49. break;
  50. case "kiwi":
  51. if (isWorkDay) {
  52. System.out.printf("%.2f", quantity * 2.70);
  53. }else if (weekEnd){
  54. System.out.printf("%.2f",quantity * 3.00);
  55. }
  56. break;
  57. case "pineapple":
  58. if (isWorkDay) {
  59. System.out.printf("%.2f",quantity * 5.50);
  60. } else if (weekEnd) {
  61. System.out.printf("%.2f", quantity * 5.60);
  62. }
  63. break;
  64. case "grapes":
  65. if (isWorkDay) {
  66. System.out.printf("%.2f",quantity * 3.85);
  67. }else if (weekEnd) {
  68. System.out.printf("%.2f", quantity * 4.00);
  69. }
  70. break;
  71. default:
  72. System.out.println("There is not such commodity");
  73. }
  74.  
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement