Advertisement
tchenkov

L04u02_SmallShop

Jan 23rd, 2017
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.17 KB | None | 0 0
  1. package Uprajneniq;
  2.  
  3. import java.text.DecimalFormat;
  4. import java.util.Scanner;
  5.  
  6. /**
  7.  * Created by todor on 23.01.2017 г..
  8.  */
  9. public class u02_SmallShop {
  10.     public static void main(String[] args) {
  11.  
  12.         Scanner scan = new Scanner(System.in);
  13.  
  14.         String product = scan.nextLine().toLowerCase();
  15.         String city = scan.nextLine().toLowerCase();
  16.         double quantity = Double.parseDouble(scan.nextLine());
  17.         DecimalFormat df = new DecimalFormat("#.######");
  18.  
  19.         double price = 0;
  20.  
  21.         if (city.equals("sofia")) {
  22.             if (product.equals("coffee")) {
  23.                 price = 0.5;
  24.             }
  25.             else if (product.equals("water")) {
  26.                 price = 0.8;
  27.             }
  28.             else if (product.equals("beer")) {
  29.                 price = 1.2;
  30.             }
  31.             else if (product.equals("sweets")) {
  32.                 price = 1.45;
  33.             }
  34.             else if (product.equals("peanuts")) {
  35.                 price = 1.6;
  36.             }
  37.         }
  38.         else if (city.equals("plovdiv")) {
  39.             if (product.equals("coffee")) {
  40.                 price = 0.4;
  41.             }
  42.             else if (product.equals("water")) {
  43.                 price = 0.7;
  44.             }
  45.             else if (product.equals("beer")) {
  46.                 price = 1.15;
  47.             }
  48.             else if (product.equals("sweets")) {
  49.                 price = 1.3;
  50.             }
  51.             else if (product.equals("peanuts")) {
  52.                 price = 1.5;
  53.             }
  54.         }
  55.         else if (city.equals("varna")) {
  56.             if (product.equals("coffee")) {
  57.                 price = 0.45;
  58.             }
  59.             else if (product.equals("water")) {
  60.                 price = 0.7;
  61.             }
  62.             else if (product.equals("beer")) {
  63.                 price = 1.1;
  64.             }
  65.             else if (product.equals("sweets")) {
  66.                 price = 1.35;
  67.             }
  68.             else if (product.equals("peanuts")) {
  69.                 price = 1.55;
  70.             }
  71.         }
  72.  
  73.         double total = price * quantity;
  74.  
  75.         System.out.printf("%s", df.format(total).replace(",", "."));
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement