Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ProgrammingBasics.NestedConditionalStatements;
- import java.util.Scanner;
- public class SmallShop {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String product = scanner.nextLine().toLowerCase();
- String city = scanner.nextLine().toLowerCase();
- double count = Double.parseDouble(scanner.nextLine());
- double price = 0;
- price = getPrice(product, city, price, "sofia", 0.50, 0.80, 1.20, 1.45, 1.60);
- price = getPrice(product, city, price, "plovdiv", 0.40, 0.70, 1.15, 1.30, 1.50);
- price = getPrice(product, city, price, "varna", 0.45, 0.70, 1.10, 1.35, 1.55);
- System.out.println(count * price);
- }
- private static double getPrice(String product, String city, double price, String sofia, double v, double v2, double v3, double v4, double v5) {
- if (city.equals(sofia)) {
- switch (product) {
- case "coffee":
- price = v;
- break;
- case "water":
- price = v2;
- break;
- case "beer":
- price = v3;
- break;
- case "sweets":
- price = v4;
- break;
- case "peanuts":
- price = v5;
- break;
- }
- }
- return price;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement