Advertisement
Guest User

08. Fruit Shop

a guest
Feb 27th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.00 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FruitShop {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         String fruit = scan.nextLine();
  8.         String day = scan.nextLine();
  9.         double quantity = Double.parseDouble(scan.nextLine());
  10.         double price = 0;
  11.         if ("Monday".equals(day) || "Tuesday".equals(day) || "Wednesday".equals(day) || "Thursday".equals(day) || "Friday".equals(day)) {
  12.             if (fruit.equals("banana")) {
  13.                 price = quantity * 2.5;
  14.             } else if (fruit.equals("apple")) {
  15.                 price = quantity * 1.20;
  16.             } else if (fruit.equals("orange")) {
  17.                 price = quantity * 0.85;
  18.             } else if (fruit.equals("grapefruit")) {
  19.                 price = quantity * 1.45;
  20.             } else if (fruit.equals("kiwi")) {
  21.                 price = quantity * 2.70;
  22.             } else if (fruit.equals("pineapple")) {
  23.                 price = quantity * 5.50;
  24.             } else if (fruit.equals("grapes")) {
  25.                 price = quantity * 3.85;
  26.             } else {
  27.                 System.out.println("error");
  28.             }
  29.  
  30.         } else if ("Saturday".equals(day) || "Sunday".equals(day)) {
  31.             if (fruit.equals("banana")) {
  32.                 price = quantity * 2.7;
  33.             } else if (fruit.equals("apple")) {
  34.                 price = quantity * 1.25;
  35.             } else if (fruit.equals("orange")) {
  36.                 price = quantity * 0.9;
  37.             } else if (fruit.equals("grapefruit")) {
  38.                 price = quantity * 1.6;
  39.             } else if (fruit.equals("kiwi")) {
  40.                 price = quantity * 3.0;
  41.             } else if (fruit.equals("pineapple")) {
  42.                 price = quantity * 5.60;
  43.             } else if (fruit.equals("grapes")) {
  44.                 price = quantity * 4.2;
  45.             } else {
  46.                 System.out.println("error");
  47.             }
  48.             System.out.println(price);
  49.         }
  50.     }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement