martinvalchev

Fruit Shop

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