danisun18

Fruit Shop

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