Advertisement
psi_mmobile

Untitled

May 16th, 2022
771
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  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 drink = scanner.next();
  6.         String sugar = scanner.next();
  7.         int numberOfOrders = scanner.nextInt();
  8.        
  9.         double espressoPrice = 0.9;
  10.         double cappuccinoPrice = 1.0;
  11.         double teaPrice = 0.5;
  12.        
  13.         double totalPrice = 0.0;
  14.         double discount = 0.0;
  15.        
  16.         switch (sugar) {
  17.             case "Normal" : espressoPrice += 0.1; cappuccinoPrice += 0.2; teaPrice += 0.1; break;
  18.             case "Extra" : espressoPrice += 0.3; cappuccinoPrice += 0.6; teaPrice += 0.2; break;
  19.             default : discount = 0.35;
  20.         }
  21.        
  22.         switch (drink) {
  23.             case "Espresso" : totalPrice = numberOfOrders * espressoPrice * (1 - discount); break;
  24.             case "Cappuccino" : totalPrice = numberOfOrders * cappuccinoPrice * (1 - discount); break;
  25.             default : totalPrice = numberOfOrders * teaPrice * (1 - discount);
  26.         }
  27.        
  28.         if (drink.equals("Espresso") && numberOfOrders >= 5) {
  29.             totalPrice = totalPrice * 0.75;
  30.         }
  31.        
  32.         if (totalPrice > 15) {
  33.             totalPrice = totalPrice * 0.8;
  34.         }
  35.        
  36.         System.out.printf("You bought %d cups of %s for %.2f lv.",numberOfOrders,drink,totalPrice);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement