Advertisement
Deiancom

Small Shop method

Jan 29th, 2020
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. package ProgrammingBasics.NestedConditionalStatements;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class SmallShop {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String product = scanner.nextLine().toLowerCase();
  9.         String city = scanner.nextLine().toLowerCase();
  10.         double count = Double.parseDouble(scanner.nextLine());
  11.         double price = 0;
  12.         price = getPrice(product, city, price, "sofia", 0.50, 0.80, 1.20, 1.45, 1.60);
  13.         price = getPrice(product, city, price, "plovdiv", 0.40, 0.70, 1.15, 1.30, 1.50);
  14.         price = getPrice(product, city, price, "varna", 0.45, 0.70, 1.10, 1.35, 1.55);
  15.         System.out.println(count * price);
  16.     }
  17.  
  18.     private static double getPrice(String product, String city, double price, String sofia, double v, double v2, double v3, double v4, double v5) {
  19.         if (city.equals(sofia)) {
  20.             switch (product) {
  21.                 case "coffee":
  22.                     price = v;
  23.                     break;
  24.                 case "water":
  25.                     price = v2;
  26.                     break;
  27.                 case "beer":
  28.                     price = v3;
  29.                     break;
  30.                 case "sweets":
  31.                     price = v4;
  32.                     break;
  33.                 case "peanuts":
  34.                     price = v5;
  35.                     break;
  36.             }
  37.         }
  38.         return price;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement