Advertisement
psi_mmobile

Untitled

May 16th, 2022
821
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. public class MyClass {
  3.     public static void main(String args[]) {
  4.         Scanner scanner = new Scanner(System.in);
  5.         String product = scanner.next();
  6.         String city = scanner.next();
  7.         int quantity = scanner.nextInt();
  8.        
  9.         double coffeePrice = 0.45;
  10.         double waterPrice = 0.7;
  11.         double beerPrice = 1.1;
  12.         double sweetsPrice = 1.35;
  13.         double peanutsPrice = 1.55;
  14.        
  15.         switch (city) {
  16.             case "Sofia" : coffeePrice += 0.05;  waterPrice += 0.1; beerPrice += 0.1; sweetsPrice += 0.1; peanutsPrice +=0.05; break;
  17.             case "Plovdiv" : coffeePrice -= 0.05; beerPrice += 0.05; sweetsPrice -= 0.05; peanutsPrice -= 0.05; break;
  18.         }
  19.         switch (product) {
  20.             case "coffee" : System.out.printf("%.2f", coffeePrice * quantity); break;
  21.             case "water" : System.out.printf("%.2f", waterPrice * quantity); break;
  22.             case "beer" : System.out.printf("%.2f", beerPrice * quantity); break;
  23.             case "sweets" : System.out.printf("%.2f", sweetsPrice * quantity); break;
  24.             case "peanuts" : System.out.printf("%.2f", peanutsPrice * quantity); break;
  25.         }
  26.     }
  27. }
Advertisement
RAW Paste Data Copied
Advertisement