Advertisement
GabrielHr00

11.FruitShop

Jun 23rd, 2024
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.11 KB | None | 0 0
  1. package TasksWeek3;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class _11_FruitShop {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String fruit = scanner.nextLine();
  10.         String weekday = scanner.nextLine();
  11.         double number = Double.parseDouble(scanner.nextLine());
  12.         double price = 0.0;
  13.  
  14.         switch (weekday) {
  15.  
  16.             case "Monday","Tuesday","Wednesday","Thursday","Friday" -> {
  17.                 if (fruit.equals("banana"))
  18.                     price = number * 2.50;
  19.                 else if (fruit.equals("apple"))
  20.                     price = number * 1.20;
  21.                 else if (fruit.equals("orange"))
  22.                     price = number * 0.85;
  23.                 else if (fruit.equals("grapefruit"))
  24.                     price = number * 1.45;
  25.                 else if (fruit.equals("kiwi"))
  26.                     price = number * 2.70;
  27.                 else if (fruit.equals("pineapple"))
  28.                     price = number * 5.50;
  29.                 else if (fruit.equals("grapes"))
  30.                     price = number * 3.85;
  31.                 else
  32.                     System.out.println("error");
  33.             }
  34.             case "Saturday","Sunday" -> {
  35.                 if (fruit.equals("banana"))
  36.                     price = number * 2.70;
  37.                 else if (fruit.equals("apple"))
  38.                     price = number * 1.25;
  39.                 else if (fruit.equals("orange"))
  40.                     price = number * 0.90;
  41.                 else if (fruit.equals("grapefruit"))
  42.                     price = number * 1.60;
  43.                 else if (fruit.equals("kiwi"))
  44.                     price = number * 3.00;
  45.                 else if (fruit.equals("pineapple"))
  46.                     price = number * 5.60;
  47.                 else if (fruit.equals("grapes"))
  48.                     price = number * 4.20;
  49.                 else
  50.                     System.out.println("error");
  51.             }
  52.             default -> System.out.println("error");
  53.         }
  54.  
  55.         if (price != 0.0) {
  56.             System.out.printf("%.2f",price);
  57.         }
  58.  
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement