Advertisement
SvetlanPetrova

Fruit Shop SoftUni

Apr 15th, 2021
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.22 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.  
  10.         boolean iserror = false;
  11.  
  12.         double price = 0.0d;
  13.  
  14. if ("Monday".equals(day) || "Tuesday".equals(day) || "Wednesday".equals(day) || "Thursday".equals(day) || "Friday".equals(day)) {
  15.     switch (fruit) {
  16.         case "banana":
  17.             price = 2.50d;
  18. //            System.out.printf("%.2f%n", price * quantity);
  19.             break;
  20.         case "apple":
  21.             price = 1.20d;
  22. //            System.out.printf("%.2f%n", price * quantity);
  23.             break;
  24.         case "orange":
  25.             price = 0.85d;
  26. //            System.out.printf("%.2f%n", price * quantity);
  27.             break;
  28.         case "grapefruit":
  29.             price = 1.45d;
  30. //            System.out.printf("%.2f%n", price * quantity);
  31.             break;
  32.         case "kiwi":
  33.             price = 2.70d;
  34. //            System.out.printf("%.2f%n", price * quantity);
  35.             break;
  36.         case "pineapple":
  37.             price = 5.50d;
  38. //            System.out.printf("%.2f%n", price * quantity);
  39.             break;
  40.         case "grapes":
  41.             price = 3.85d;
  42. //            System.out.printf("%.2f%n", price * quantity);
  43.             break;
  44.         default:
  45.             iserror = true;
  46.             break;
  47.     }
  48. }
  49.             else if ("Saturday".equals(day) || "Sunday".equals(day)) {
  50.                 switch (fruit) {
  51.                     case "banana":
  52.                         price = 2.70d;
  53. //                        System.out.printf("%.2f%n", price * quantity);
  54.                         break;
  55.                     case "apple":
  56.                         price = 1.25d;
  57. //                        System.out.printf("%.2f%n", price * quantity);
  58.                         break;
  59.                     case "orange":
  60.                         price = 0.90d;
  61. //                        System.out.printf("%.2f%n", price * quantity);
  62.                         break;
  63.                     case "grapefruit":
  64.                         price = 1.60d;
  65. //                        System.out.printf("%.2f%n", price * quantity);
  66.                         break;
  67.                     case "kiwi":
  68.                         price = 3.00d;
  69. //                        System.out.printf("%.2f%n", price * quantity);
  70.                         break;
  71.                     case "pineapple":
  72.                         price = 5.60d;
  73. //                        System.out.printf("%.2f%n", price * quantity);
  74.                         break;
  75.                     case "grapes":
  76.                         price = 4.20d;
  77. //                        System.out.printf("%.2f%n", price * quantity);
  78.                         break;
  79.                     default:
  80.                         iserror = true;
  81.                         break;
  82.                 }
  83.         }
  84.             else {
  85.                 iserror = true;
  86.             }
  87.  
  88.         if (iserror){
  89.             System.out.println("error");
  90.         }else{
  91.             System.out.printf("%.2f%n", price * quantity);
  92.         }
  93.  
  94.     }
  95. }
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement