Advertisement
ivanmitkoff

Untitled

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