Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.65 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CoffeeMachine {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6. //•   Първи ред - напитка - текст с възможности"Espresso", "Cappuccino" или "Tea"
  7. //•   Втори ред - захар - текст  с възможности "Without", "Normal" или "Extra"
  8. //•   Трети ред - брой напитки - цяло число в интервала [1… 50]
  9.         String drink = scanner.nextLine();
  10.         String sugar = scanner.nextLine();
  11.         int countDrinks = Integer.parseInt(scanner.nextLine());
  12.         double price = 0;
  13. //•   При избрана напитка без захар има 35% отстъпка.
  14. //•   При избрана напитка "Espresso" и закупени поне 5 броя, има 25% отстъпка.
  15. //•   При сума надвишава 15 лева, 20% отстъпка от крайната цена,
  16. //Отстъпките се прилагат в реда на тяхното описване.
  17.  
  18.         // Без захар    Нормално    Допълнително захар
  19.         // Еспресо   0.90 лв./бр.    1 лв. /бр.  1.20 лв. /бр.
  20.         //  Капучино    1.00 лв. /бр.   1.20 лв. /бр.   1.60 лв. /бр.
  21.         // Чай   0.50 лв. /бр.   0.60 лв. /бр.   0.70 лв. /бр.
  22.         switch (drink) {
  23.             case "Espresso":
  24.                 if ("Without".equals(sugar)) {
  25.                     price = countDrinks * (0.9 * 0.65);
  26.                     if (countDrinks >= 5) {
  27.                         price = price * 0.75;
  28.                     }
  29.                     if (price > 15) {
  30.                         price = price * 0.8;
  31.                     }
  32.  
  33.                 } else if ("Normal".equals(sugar)) {
  34.                     price = countDrinks * 1.0;
  35.                     if (price > 15) {
  36.                         price = price * 0.8;
  37.                     }
  38.  
  39.  
  40.                 } else {
  41.                     price = countDrinks * 1.2;
  42.                     if (price > 15) {
  43.                         price = price * 0.8;
  44.                     }
  45.  
  46.                 }
  47.                 break;
  48.             case "Cappuccino":
  49.                 if ("Without".equals(sugar)) {
  50.                     price = countDrinks * (1.0 * 0.35);
  51.  
  52.                     if (price > 15) {
  53.                         price = price * 0.8;
  54.                     }
  55.  
  56.                 } else if ("Normal".equals(sugar)) {
  57.                     price = countDrinks * 1.2;
  58.                     if (price > 15) {
  59.                         price = price * 0.8;
  60.                     }
  61.  
  62.  
  63.                 } else {
  64.                     price = countDrinks * 1.6;
  65.                     if (price > 15) {
  66.                         price = price * 0.8;
  67.                     }
  68.  
  69.                 }
  70.                 break;
  71.             case "Tea":
  72.                 if ("Without".equals(sugar)) {
  73.                     price = countDrinks * (0.5 * 0.35);
  74.  
  75.                     if (price > 15) {
  76.                         price = price * 0.8;
  77.                     }
  78.  
  79.                 } else if ("Normal".equals(sugar)) {
  80.                     price = countDrinks * 0.6;
  81.                     if (price > 15) {
  82.                         price = price * 0.8;
  83.                     }
  84.  
  85.  
  86.                 } else {
  87.                     price = countDrinks * 0.7;
  88.                     if (price > 15) {
  89.                         price = price * 0.8;
  90.                     }
  91.  
  92.                 }
  93.                 break;
  94.  
  95.  
  96.         }
  97.         System.out.printf("You bought %d cups of %s for %.2f lv.", countDrinks, drink,price);
  98.  
  99.  
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement