Advertisement
finderabc

v- fruitShop (yan-19)

Feb 2nd, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 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.  
  11.         boolean isValidDay = true;
  12.         boolean isValidFruit = true;
  13.         double price = 0.0;
  14.  
  15.         if (("Monday".equals(day)) || "Tuesday".equals(day) || "Wednesday".equals(day) ||
  16.                 "Thursday".equals(day) || "Friday".equals(day)) {
  17.             if ("banana".equals(fruit)) {
  18.                 price = 2.50;
  19.             } else if ("apple".equals(fruit)) {
  20.                 price = 1.20;
  21.             } else if ("orange".equals(fruit)) {
  22.                 price = 0.85;
  23.             } else if ("grapefruit".equals(fruit)) {
  24.                 price = 1.45;
  25.             } else if ("kiwi".equals(fruit)) {
  26.                 price = 2.70;
  27.             } else if ("pineapple".equals(fruit)) {
  28.                 price = 5.50;
  29.             } else if ("grapes".equals(fruit)) {
  30.                 price = 3.85;
  31.             }else {
  32.                 isValidFruit = false;
  33.             }
  34.         } else if ("Saturday".equals(day) || "Sunday".equals(day)) {
  35.             if ("banana".equals(fruit)) {
  36.                 price = 2.70;
  37.             } else if ("apple".equals(fruit)) {
  38.                 price = 1.25;
  39.             } else if ("orange".equals(fruit)) {
  40.                 price = 0.90;
  41.             } else if ("grapefruit".equals(fruit)) {
  42.                 price = 1.60;
  43.             } else if ("kiwi".equals(fruit)) {
  44.                 price = 3.00;
  45.             } else if ("pineapple".equals(fruit)) {
  46.                 price = 5.60;
  47.             } else if ("grapes".equals(fruit)) {
  48.                 price = 4.20;
  49.             }else{
  50.                 isValidFruit = false;
  51.             }
  52.         }else{
  53.             isValidDay = false;
  54.         }
  55.         if(!isValidFruit || !isValidDay){
  56.             System.out.println("error");
  57.         }else{
  58.             price *= quantity;
  59.             System.out.printf("%.2f",price);
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement