Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SmallShop_05 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- //продукт -> String
- //град -> String
- //количество -> double
- //крайна цена = количество * ед.цена за продукт
- String product = scanner.nextLine();
- String town = scanner.nextLine();
- double quantity = Double.parseDouble(scanner.nextLine());
- double pricePerProduct = 0; //ед.цена за продукт
- //проверка за града -> "Sofia", "Plovdiv", "Varna"
- switch (town) {
- case "Sofia":
- //проверка за продукт -> "coffee", "water", "beer", "sweets", "peanuts"
- if (product.equals("coffee")) {
- pricePerProduct = 0.50;
- } else if(product.equals("water")){
- pricePerProduct = 0.80;
- } else if (product.equals("beer")) {
- pricePerProduct = 1.20;
- } else if(product.equals("sweets")) {
- pricePerProduct = 1.45;
- } else if (product.equals("peanuts")) {
- pricePerProduct = 1.60;
- }
- break;
- case "Plovdiv":
- //проверка за продукт -> "coffee", "water", "beer", "sweets", "peanuts"
- if (product.equals("coffee")) {
- pricePerProduct = 0.40;
- } else if(product.equals("water")){
- pricePerProduct = 0.70;
- } else if (product.equals("beer")) {
- pricePerProduct = 1.15;
- } else if(product.equals("sweets")) {
- pricePerProduct = 1.30;
- } else if (product.equals("peanuts")) {
- pricePerProduct = 1.50;
- }
- break;
- case "Varna":
- //проверка за продукт -> "coffee", "water", "beer", "sweets", "peanuts"
- if (product.equals("coffee")) {
- pricePerProduct = 0.45;
- } else if(product.equals("water")){
- pricePerProduct = 0.70;
- } else if (product.equals("beer")) {
- pricePerProduct = 1.10;
- } else if(product.equals("sweets")) {
- pricePerProduct = 1.35;
- } else if (product.equals("peanuts")) {
- pricePerProduct = 1.55;
- }
- break;
- }
- //знаем ед. цена за продукт
- double finalPrice = quantity * pricePerProduct;
- System.out.println(finalPrice);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement