myrdok123

05. Small Shop

Jun 1st, 2024
788
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.47 KB | None | 0 0
  1. package ConditionalStatementsAdvance;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class SmallShop_05 {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         String product = scanner.nextLine();
  11.         String town = scanner.nextLine();
  12.         double quantity = Double.parseDouble(scanner.nextLine());
  13.  
  14.         //coffee    water   beer    sweets  peanuts
  15. /* Sofia  0.50      0.80    1.20    1.45    1.60
  16. Plovdiv   0.40      0.70    1.15    1.30    1.50
  17. Varna      0.45     0.70    1.10    1.35    1.55*/
  18.  
  19.  
  20.         double totalPrice = 0;
  21.         switch (product){
  22.             case "coffee":
  23.                 if (town.equals("Sofia")) {
  24.                     totalPrice = quantity * 0.50;
  25.                 } else if (town.equals("Plovdiv")) {
  26.                     totalPrice = quantity * 0.40;
  27.                 } else if (town.equals("Varna")) {
  28.                     totalPrice = quantity * 0.45;
  29.                 }
  30.                 break;
  31.  
  32.             case "water":
  33.                 if(town.equals("Sofia")){
  34.                     totalPrice = quantity * 0.80;
  35.                 } else if (town.equals("Plovdiv")) {
  36.                     totalPrice = quantity * 0.70;
  37.                 } else if (town.equals("Varna")) {
  38.                     totalPrice = quantity * 0.70;
  39.                 }
  40.                 break;
  41.  
  42.             case "beer":
  43.                 if (town.equals("Sofia")){
  44.                     totalPrice = quantity * 1.20;
  45.                 } else if (town.equals("Plovdiv")) {
  46.                     totalPrice = quantity * 1.15;
  47.                 } else if (town.equals("Varna")) {
  48.                     totalPrice = quantity * 1.10;
  49.                 }
  50.                 break;
  51.  
  52.             case "sweets":
  53.                 if (town.equals("Sofia")){
  54.                     totalPrice = quantity * 1.45;
  55.                 } else if (town.equals("Plovdiv")) {
  56.                     totalPrice = quantity * 1.30;
  57.                 } else if (town.equals("Varna")) {
  58.                     totalPrice = quantity * 1.35;
  59.                 }
  60.                 break;
  61.  
  62.             case "peanuts":
  63.                 if (town.equals("Sofia")){
  64.                     totalPrice = quantity * 1.60;
  65.                 } else if (town.equals("Plovdiv")) {
  66.                     totalPrice = quantity * 1.50;
  67.                 } else if (town.equals("Varna")) {
  68.                     totalPrice = quantity * 1.55;
  69.                 }
  70.                 break;
  71.         }
  72.  
  73.  
  74.         System.out.println(totalPrice);
  75.  
  76.  
  77.  
  78.     }
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment