Advertisement
desislava_topuzakova

05. Small Shop

Apr 17th, 2021
996
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.81 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SmallShop_05 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         //продукт -> String
  7.         //град -> String
  8.         //количество -> double
  9.         //крайна цена = количество * ед.цена за продукт
  10.         String product = scanner.nextLine();
  11.         String town = scanner.nextLine();
  12.         double quantity = Double.parseDouble(scanner.nextLine());
  13.  
  14.         double pricePerProduct = 0; //ед.цена за продукт
  15.  
  16.         //проверка за града -> "Sofia", "Plovdiv", "Varna"
  17.         switch (town) {
  18.             case "Sofia":
  19.                 //проверка за продукт -> "coffee", "water", "beer", "sweets", "peanuts"
  20.                 if (product.equals("coffee")) {
  21.                     pricePerProduct = 0.50;
  22.                 } else if(product.equals("water")){
  23.                     pricePerProduct = 0.80;
  24.                 } else if (product.equals("beer")) {
  25.                     pricePerProduct = 1.20;
  26.                 } else if(product.equals("sweets")) {
  27.                     pricePerProduct = 1.45;
  28.                 } else if (product.equals("peanuts")) {
  29.                     pricePerProduct = 1.60;
  30.                 }
  31.                 break;
  32.             case "Plovdiv":
  33.                 //проверка за продукт -> "coffee", "water", "beer", "sweets", "peanuts"
  34.                 if (product.equals("coffee")) {
  35.                     pricePerProduct = 0.40;
  36.                 } else if(product.equals("water")){
  37.                     pricePerProduct = 0.70;
  38.                 } else if (product.equals("beer")) {
  39.                     pricePerProduct = 1.15;
  40.                 } else if(product.equals("sweets")) {
  41.                     pricePerProduct = 1.30;
  42.                 } else if (product.equals("peanuts")) {
  43.                     pricePerProduct = 1.50;
  44.                 }
  45.                 break;
  46.             case "Varna":
  47.                 //проверка за продукт -> "coffee", "water", "beer", "sweets", "peanuts"
  48.                 if (product.equals("coffee")) {
  49.                     pricePerProduct = 0.45;
  50.                 } else if(product.equals("water")){
  51.                     pricePerProduct = 0.70;
  52.                 } else if (product.equals("beer")) {
  53.                     pricePerProduct = 1.10;
  54.                 } else if(product.equals("sweets")) {
  55.                     pricePerProduct = 1.35;
  56.                 } else if (product.equals("peanuts")) {
  57.                     pricePerProduct = 1.55;
  58.                 }
  59.                 break;
  60.         }
  61.  
  62.         //знаем ед. цена за продукт
  63.         double finalPrice = quantity * pricePerProduct;
  64.         System.out.println(finalPrice);
  65.  
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement