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());
- boolean iserror = false;
- double price = 0.0d;
- if ("Monday".equals(day) || "Tuesday".equals(day) || "Wednesday".equals(day) || "Thursday".equals(day) || "Friday".equals(day)) {
- switch (fruit) {
- case "banana":
- price = 2.50d;
- // System.out.printf("%.2f%n", price * quantity);
- break;
- case "apple":
- price = 1.20d;
- // System.out.printf("%.2f%n", price * quantity);
- break;
- case "orange":
- price = 0.85d;
- // System.out.printf("%.2f%n", price * quantity);
- break;
- case "grapefruit":
- price = 1.45d;
- // System.out.printf("%.2f%n", price * quantity);
- break;
- case "kiwi":
- price = 2.70d;
- // System.out.printf("%.2f%n", price * quantity);
- break;
- case "pineapple":
- price = 5.50d;
- // System.out.printf("%.2f%n", price * quantity);
- break;
- case "grapes":
- price = 3.85d;
- // System.out.printf("%.2f%n", price * quantity);
- break;
- default:
- iserror = true;
- break;
- }
- }
- else if ("Saturday".equals(day) || "Sunday".equals(day)) {
- switch (fruit) {
- case "banana":
- price = 2.70d;
- // System.out.printf("%.2f%n", price * quantity);
- break;
- case "apple":
- price = 1.25d;
- // System.out.printf("%.2f%n", price * quantity);
- break;
- case "orange":
- price = 0.90d;
- // System.out.printf("%.2f%n", price * quantity);
- break;
- case "grapefruit":
- price = 1.60d;
- // System.out.printf("%.2f%n", price * quantity);
- break;
- case "kiwi":
- price = 3.00d;
- // System.out.printf("%.2f%n", price * quantity);
- break;
- case "pineapple":
- price = 5.60d;
- // System.out.printf("%.2f%n", price * quantity);
- break;
- case "grapes":
- price = 4.20d;
- // System.out.printf("%.2f%n", price * quantity);
- break;
- default:
- iserror = true;
- break;
- }
- }
- else {
- iserror = true;
- }
- if (iserror){
- System.out.println("error");
- }else{
- System.out.printf("%.2f%n", price * quantity);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement