Advertisement
stoyanoff

FruitShop-new

Jun 23rd, 2020
1,219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.75 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Test {
  4.     public static void main(String[] args) {
  5.         Scanner myScan = new Scanner(System.in);
  6.  
  7.         String fruitType = myScan.nextLine();
  8.         String dayOfTheWeek = myScan.nextLine();
  9.         double quantity = Double.parseDouble(myScan.nextLine());
  10.         double totalPrice = 0;
  11.         switch (dayOfTheWeek) {
  12.  
  13.             case "Monday":
  14.             case "Tuesday":
  15.             case "Wednesday":
  16.             case "Thursday":
  17.             case "Friday":
  18.                 switch (fruitType) {
  19.                     case "banana":
  20.                         totalPrice = quantity * 2.5;
  21.                         break;
  22.                     case "apple":
  23.                         totalPrice = quantity * 1.2;
  24.                         break;
  25.                     case "orange":
  26.                         totalPrice = quantity * 0.85;
  27.                         break;
  28.                     case "grapefruit":
  29.                         totalPrice = quantity * 1.45;
  30.                         break;
  31.                     case "kiwi":
  32.                         totalPrice = quantity * 2.7;
  33.                         break;
  34.                     case "pineapple":
  35.                         totalPrice = quantity * 5.5;
  36.                         break;
  37.                     case "grapes":
  38.                         totalPrice = quantity * 3.85;
  39.                         break;
  40.                     default:
  41.                         System.out.println("error");
  42.                         break;
  43.  
  44.                 }
  45.                 break;
  46.  
  47.  
  48.             case "Saturday":
  49.             case "Sunday":
  50.                 switch (fruitType) {
  51.                     case "banana":
  52.                         totalPrice = quantity * 2.7;
  53.                         break;
  54.                     case "apple":
  55.                         totalPrice = quantity * 1.25;
  56.                         break;
  57.                     case "orange":
  58.                         totalPrice = quantity * 0.9;
  59.                         break;
  60.                     case "grapefruit":
  61.                         totalPrice = quantity * 1.6;
  62.                         break;
  63.                     case "kiwi":
  64.                         totalPrice = quantity * 3.0;
  65.                         break;
  66.                     case "pineapple":
  67.                         totalPrice = quantity * 5.6;
  68.                         break;
  69.                     case "grapes":
  70.                         totalPrice = quantity * 4.2;
  71.                         break;
  72.                     default:
  73.                         System.out.println("error");
  74.                         break;
  75.                 }
  76.                 break;
  77.  
  78.             default:
  79.                 System.out.println("error");
  80.                 break;
  81.  
  82.         }
  83.         if (totalPrice > 0) {
  84.             System.out.printf("%.2f", totalPrice);
  85.         }
  86.  
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement