Advertisement
Guest User

Untitled

a guest
Nov 9th, 2017
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. package _04_Polymorphism.EXERCISES;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class test {
  6.     public static void main(String[] args) {
  7.         Scanner console = new Scanner(System.in);
  8.  
  9.         String product = console.nextLine().toLowerCase();
  10.         String city = console.nextLine().toLowerCase();
  11.         Double quantity = Double.parseDouble(console.nextLine());
  12.  
  13.         double price = -1;
  14.  
  15.  
  16.         if (city.equals("sofia")) {
  17.             if (product.equals("coffee")) {
  18.                 price = 0.50;
  19.             } else if (product.equals("water")) {
  20.                 price = 0.80;
  21.             } else if (product.equals("beer")) {
  22.                 price = 1.20;
  23.             } else if (product.equals("sweets")) {
  24.                 price = 1.45;
  25.             } else if (product.equals("peanuts")) {
  26.                 price = 1.60;
  27.             }
  28.         } else if (city.equals("plovdiv")) {
  29.             if (product.equals("coffee")) {
  30.                 price = 0.40;
  31.             } else if (product.equals("water")) {
  32.                 price = 0.70;
  33.             } else if (product.equals("beer")) {
  34.                 price = 1.15;
  35.             } else if (product.equals("sweets")) {
  36.                 price = 1.30;
  37.             } else if (product.equals("peanuts")) {
  38.                 price = 1.50;
  39.             }
  40.         } else if (city.equals("varna")) {
  41.             if (product.equals("coffee")) {
  42.                 price = 0.45;
  43.             } else if (product.equals("water")) {
  44.                 price = 0.70;
  45.             } else if (product.equals("beer")) {
  46.                 price = 1.10;
  47.             } else if (product.equals("sweets")) {
  48.                 price = 1.35;
  49.             } else if (product.equals("peanuts")) {
  50.                 price = 1.55;
  51.             }
  52.         }
  53.         double endPrice = quantity * price;
  54.  
  55.         System.out.println(endPrice);
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement