Advertisement
veronikaaa86

11. Fruit Shop

Oct 16th, 2021
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. package conditionalStatementsAdvanced;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P11FruitShop {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String fruit = scanner.nextLine();
  10. String dayOfWeek = scanner.nextLine();
  11. double quantity = Double.parseDouble(scanner.nextLine());
  12.  
  13. boolean workingDay = dayOfWeek.equals("Monday") ||
  14. dayOfWeek.equals("Tuesday") ||
  15. dayOfWeek.equals("Wednesday") ||
  16. dayOfWeek.equals("Thursday") ||
  17. dayOfWeek.equals("Friday");
  18.  
  19. boolean weekend = dayOfWeek.equals("Saturday") || dayOfWeek.equals("Sunday");
  20.  
  21. boolean flag = true;
  22.  
  23. double priceKG = 0;
  24. if (workingDay) {
  25. if ("banana".equals(fruit)) {
  26. priceKG = 2.50;
  27. } else if ("apple".equals(fruit)) {
  28. priceKG = 1.20;
  29. } else if ("orange".equals(fruit)) {
  30. priceKG = 0.85;
  31. } else if ("grapefruit".equals(fruit)) {
  32. priceKG = 1.45;
  33. } else if ("kiwi".equals(fruit)) {
  34. priceKG = 2.70;
  35. } else if ("pineapple".equals(fruit)) {
  36. priceKG = 5.50;
  37. } else if ("grapes".equals(fruit)) {
  38. priceKG = 3.85;
  39. } else {
  40. flag = false;
  41. }
  42. } else if (weekend) {
  43. if ("banana".equals(fruit)) {
  44. priceKG = 2.70;
  45. } else if ("apple".equals(fruit)) {
  46. priceKG = 1.25;
  47. } else if ("orange".equals(fruit)) {
  48. priceKG = 0.90;
  49. } else if ("grapefruit".equals(fruit)) {
  50. priceKG = 1.60;
  51. } else if ("kiwi".equals(fruit)) {
  52. priceKG = 3;
  53. } else if ("pineapple".equals(fruit)) {
  54. priceKG = 5.60;
  55. } else if ("grapes".equals(fruit)) {
  56. priceKG = 4.20;
  57. } else {
  58. flag = false;
  59. }
  60. } else {
  61. flag = false;
  62. }
  63. if (flag) {
  64. double totalPrice = quantity * priceKG;
  65. System.out.printf("%.2f", totalPrice);
  66.  
  67. } else {
  68. System.out.println("error");
  69. }
  70. }
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement