Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class FruitShop {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String fruit = scanner.nextLine();
- String day = scanner.nextLine();
- double quantity = Double.parseDouble(scanner.nextLine());
- double price = 0;
- if (day.equals("Monday")
- || day.equals("Tuesday")
- || day.equals("Wednesday")
- || day.equals("Thursday")
- || day.equals("Friday")) {
- price = switch (fruit) {
- case "banana" -> 2.50;
- case "apple" -> 1.20;
- case "orange" -> 0.85;
- case "grapefruit" -> 1.45;
- case "kiwi" -> 2.70;
- case "pineapple" -> 5.50;
- case "grapes" -> 3.85;
- default -> price;
- };
- } else if (day.equals("Saturday")
- || day.equals("Sunday")) {
- price = switch (fruit) {
- case "banana" -> 2.70;
- case "apple" -> 1.25;
- case "orange" -> 0.90;
- case "grapefruit" -> 1.60;
- case "kiwi" -> 3.00;
- case "pineapple" -> 5.60;
- case "grapes" -> 4.20;
- default -> price;
- };
- }
- if (price == 0) {
- System.out.println("error");
- } else {
- System.out.printf("%.2f\n", price * quantity);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement