Advertisement
Guest User

07. Fruit Shop

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