Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.util.Scanner;
- public class FruitShop_Lab {
- 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.0;
- if (day.equals("Monday") || day.equals("Tuesday") || day.equals("Wednesday")
- || day.equals("Thursday") || day.equals("Friday")) {
- switch (fruit) {
- case "banana":
- price = 2.50 * quantity;
- System.out.printf("%.2f", price);
- break;
- case "apple":
- price = 1.20 * quantity;
- System.out.printf("%.2f", price);
- break;
- case "orange":
- price = 0.85 * quantity;
- System.out.printf("%.2f", price);
- break;
- case "grapefruit":
- price = 1.45 * quantity;
- System.out.printf("%.2f", price);
- break;
- case "kiwi":
- price = 2.70 * quantity;
- System.out.printf("%.2f", price);
- break;
- case "pineapple":
- price = 5.50 * quantity;
- System.out.printf("%.2f", price);
- break;
- case "grapes":
- price = 3.85 * quantity;
- System.out.printf("%.2f", price);
- break;
- default:
- System.out.print("error");
- break;
- }
- } else if (day.equals("Saturday") || day.equals("Sunday")) {
- switch (fruit) {
- case "banana":
- price = 2.70 * quantity;
- System.out.printf("%.2f", price);
- break;
- case "apple":
- price = 1.25 * quantity;
- System.out.printf("%.2f", price);
- break;
- case "orange":
- price = 0.90 * quantity;
- System.out.printf("%.2f", price);
- break;
- case "grapefruit":
- price = 1.60 * quantity;
- System.out.printf("%.2f", price);
- break;
- case "kiwi":
- price = 3.00 * quantity;
- System.out.printf("%.2f", price);
- break;
- case "pineapple":
- price = 5.60 * quantity;
- System.out.printf("%.2f", price);
- break;
- case "grapes":
- price = 4.20 * quantity;
- System.out.printf("%.2f", price);
- break;
- default:
- System.out.print("error");
- break;
- }
- }else {
- System.out.print("error");
- }
- }
- }
Add Comment
Please, Sign In to add comment