stoyanoff

FruitShop-11

Jun 22nd, 2020
1,600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.64 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FruitShop_11 {
  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.                         System.out.printf("%.2f", totalPrice);
  22.                         break;
  23.                     case "apple":
  24.                         totalPrice = quantity * 1.2;
  25.                         System.out.printf("%.2f", totalPrice);
  26.                         break;
  27.                     case "orange":
  28.                         totalPrice = quantity * 0.85;
  29.                         System.out.printf("%.2f", totalPrice);
  30.                         break;
  31.                     case "grapefruit":
  32.                         totalPrice = quantity * 1.45;
  33.                         System.out.printf("%.2f", totalPrice);
  34.                         break;
  35.                     case "kiwi":
  36.                         totalPrice = quantity * 2.7;
  37.                         System.out.printf("%.2f", totalPrice);
  38.                         break;
  39.                     case "pineapple":
  40.                         totalPrice = quantity * 5.5;
  41.                         System.out.printf("%.2f", totalPrice);
  42.                         break;
  43.                     case "grapes":
  44.                         totalPrice = quantity * 3.85;
  45.                         System.out.printf("%.2f", totalPrice);
  46.                         break;
  47.                     default:
  48.                         System.out.println("error");
  49.                         break;
  50.  
  51.                 }
  52.                 break;
  53.  
  54.  
  55.             case "Saturday":
  56.             case "Sunday":
  57.                 switch (fruitType) {
  58.                     case "banana":
  59.                         totalPrice = quantity * 2.7;
  60.                         System.out.printf("%.2f", totalPrice);
  61.                         break;
  62.                     case "apple":
  63.                         totalPrice = quantity * 1.25;
  64.                         System.out.printf("%.2f", totalPrice);
  65.                         break;
  66.                     case "orange":
  67.                         totalPrice = quantity * 0.9;
  68.                         System.out.printf("%.2f", totalPrice);
  69.                         break;
  70.                     case "grapefruit":
  71.                         totalPrice = quantity * 1.6;
  72.                         System.out.printf("%.2f", totalPrice);
  73.                         break;
  74.                     case "kiwi":
  75.                         totalPrice = quantity * 3.0;
  76.                         System.out.printf("%.2f", totalPrice);
  77.                         break;
  78.                     case "pineapple":
  79.                         totalPrice = quantity * 5.6;
  80.                         System.out.printf("%.2f", totalPrice);
  81.                         break;
  82.                     case "grapes":
  83.                         totalPrice = quantity * 4.2;
  84.                         System.out.printf("%.2f", totalPrice);
  85.                         break;
  86.                     default:
  87.                         System.out.println("error");
  88.                         break;
  89.  
  90.                 }
  91.                 break;
  92.  
  93.             default:
  94.                 System.out.println("error");
  95.                 break;
  96.  
  97.         }
  98.  
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment