borkins

07. Fruit Shop

Mar 26th, 2017
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.44 KB | None | 0 0
  1. /**
  2.  * Project: Complex_Conditions - created by borkins on 2017-03-26.
  3.  */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class _07_FruitShop
  8. {
  9.     public static void main(String[] args)
  10.     {
  11.         Scanner console = new Scanner(System.in);
  12.        
  13.         String fruit = console.nextLine().toLowerCase();
  14.         String day = console.nextLine().toLowerCase();
  15.         double quantity = Double.parseDouble(console.nextLine());
  16.        
  17.         double price = -1;
  18.         boolean isWorkday = day.equals("monday") || day.equals("tuesday") ||
  19.                             day.equals("wednesday") || day.equals("thursday") ||
  20.                             day.equals("friday");
  21.         boolean isWeekend = day.equals("saturday") || day.equals("sunday");
  22.        
  23.         if (isWorkday)
  24.         {
  25.             switch (fruit)
  26.             {
  27.                 case "banana":
  28.                     price = 2.50;
  29.                     break;
  30.                 case "apple":
  31.                     price = 1.20;
  32.                     break;
  33.                 case "orange":
  34.                     price = 0.85;
  35.                     break;
  36.                 case "grapefruit":
  37.                     price = 1.45;
  38.                     break;
  39.                 case "kiwi":
  40.                     price = 2.70;
  41.                     break;
  42.                 case "pineapple":
  43.                     price = 5.50;
  44.                     break;
  45.                 case "grapes":
  46.                     price = 3.85;
  47.                     break;
  48.             }
  49.         }
  50.         else if (isWeekend)
  51.         {
  52.             switch (fruit)
  53.             {
  54.                 case "banana":
  55.                     price = 2.70;
  56.                     break;
  57.                 case "apple":
  58.                     price = 1.25;
  59.                     break;
  60.                 case "orange":
  61.                     price = 0.90;
  62.                     break;
  63.                 case "grapefruit":
  64.                     price = 1.60;
  65.                     break;
  66.                 case "kiwi":
  67.                     price = 3.00;
  68.                     break;
  69.                 case "pineapple":
  70.                     price = 5.60;
  71.                     break;
  72.                 case "grapes":
  73.                     price = 4.20;
  74.                     break;
  75.             }
  76.         }
  77.        
  78.         if (price >= 0) {
  79.             System.out.println(price * quantity);
  80.         }
  81.         else {
  82.             System.out.println("error");
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment