Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SmallShop {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String product = scanner.nextLine();
- String town = scanner.nextLine();
- double quantity = Double.parseDouble(scanner.nextLine());
- double price = 0;
- if (town.equals("Sofia")) {
- if (product.equals("coffee")) {
- price = 0.50;
- } else if (product.equals("water")) {
- price = 0.80;
- } else if (product.equals("beer")) {
- price = 1.20;
- } else if (product.equals("sweets")) {
- price = 1.45;
- } else if (product.equals("peanuts")) {
- price = 1.60;
- }
- } else if (town.equals("Plovdiv")) {
- if (product.equals("coffee")) {
- price = 0.40;
- } else if (product.equals("water")) {
- price = 0.70;
- } else if (product.equals("beer")) {
- price = 1.15;
- } else if (product.equals("sweets")) {
- price = 1.30;
- } else if (product.equals("peanuts")) {
- price = 1.50;
- }
- } else if (town.equals("Varna")) {
- if (product.equals("coffee")) {
- price = 0.45;
- } else if (product.equals("water")) {
- price = 0.70;
- } else if (product.equals("beer")) {
- price = 1.10;
- } else if (product.equals("sweets")) {
- price = 1.35;
- } else if (product.equals("peanuts")) {
- price = 1.55;
- }
- }
- System.out.println(price * quantity);
- }
- }
- ИЛИ:
- import java.util.Scanner;
- public class SmallShop {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String product = scanner.nextLine();
- String town = scanner.nextLine();
- double quantity = Double.parseDouble(scanner.nextLine());
- double price = 0;
- switch (town) {
- case "Sofia":
- switch (product) {
- case "coffee":
- price = 0.50;
- break;
- case "water":
- price = 0.80;
- break;
- case "beer":
- price = 1.20;
- break;
- case "sweets":
- price = 1.45;
- break;
- case "peanuts":
- price = 1.60;
- break;
- }
- break;
- case "Plovdiv":
- switch (product) {
- case "coffee":
- price = 0.40;
- break;
- case "water":
- price = 0.70;
- break;
- case "beer":
- price = 1.15;
- break;
- case "sweets":
- price = 1.30;
- break;
- case "peanuts":
- price = 1.50;
- break;
- }
- break;
- case "Varna":
- switch (product) {
- case "coffee":
- price = 0.45;
- break;
- case "water":
- price = 0.70;
- break;
- case "beer":
- price = 1.10;
- break;
- case "sweets":
- price = 1.35;
- break;
- case "peanuts":
- price = 1.55;
- break;
- }
- break;
- }
- System.out.println(price * quantity);
- }
- }
- ИЛИ:
- import java.util.Scanner;
- public class SmallShop {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String product = scanner.nextLine();
- String town = scanner.nextLine();
- double quantity = Double.parseDouble(scanner.nextLine());
- double price = product.equals("coffee") ? (town.equals("Sofia") ? 0.50 : town.equals("Plovdiv") ? 0.40 : town.equals("Varna") ? 0.45 : 0) :
- product.equals("water") ? (town.equals("Sofia") ? 0.80 : town.equals("Plovdiv") ? 0.70 : town.equals("Varna") ? 0.70 : 0) :
- product.equals("beer") ? (town.equals("Sofia") ? 1.20 : town.equals("Plovdiv") ? 1.15 : town.equals("Varna") ? 1.10 : 0) :
- product.equals("sweets") ? (town.equals("Sofia") ? 1.45 : town.equals("Plovdiv") ? 1.30 : town.equals("Varna") ? 1.35 : 0) :
- product.equals("peanuts") ? (town.equals("Sofia") ? 1.60 : town.equals("Plovdiv") ? 1.50 : town.equals("Varna") ? 1.55 : 0) : 0;
- System.out.println(price * quantity);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement