Advertisement
veronikaaa86

03. Coffee Machine

Apr 22nd, 2023
652
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. package examPrep;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P03CoffeeMachine {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String drink = scanner.nextLine();
  10.         String sugar = scanner.nextLine();
  11.         int countDrinks = Integer.parseInt(scanner.nextLine());
  12.  
  13.         double price = 0;
  14.         if (drink.equals("Espresso")) {
  15.             if (sugar.equals("Without")) {
  16.                 price = 0.9;
  17.             } else if (sugar.equals("Normal")) {
  18.                 price = 1;
  19.             } else if (sugar.equals("Extra")) {
  20.                 price = 1.2;
  21.             }
  22.         } else if (drink.equals("Cappuccino")) {
  23.             if (sugar.equals("Without")) {
  24.                 price = 1;
  25.             } else if (sugar.equals("Normal")) {
  26.                 price = 1.2;
  27.             } else if (sugar.equals("Extra")) {
  28.                 price = 1.6;
  29.             }
  30.         } else if (drink.equals("Tea")) {
  31.             if (sugar.equals("Without")) {
  32.                 price = 0.5;
  33.             } else if (sugar.equals("Normal")) {
  34.                 price = 0.6;
  35.             } else if (sugar.equals("Extra")) {
  36.                 price = 0.7;
  37.             }
  38.         }
  39.  
  40.         double totalPrice = price * countDrinks;
  41.  
  42.         if (sugar.equals("Without")) {
  43.             totalPrice = totalPrice * 0.65;
  44.         }
  45.  
  46.         if (drink.equals("Espresso") && countDrinks >= 5) {
  47.             totalPrice = totalPrice * 0.75;
  48.         }
  49.  
  50.         if (totalPrice > 15){
  51.             totalPrice = totalPrice * 0.80;
  52.         }
  53.  
  54.         System.out.printf("You bought %d cups of %s for %.2f lv.", countDrinks, drink, totalPrice);
  55.     }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement