Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CoffeeMachine {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- //• Първи ред - напитка - текст с възможности"Espresso", "Cappuccino" или "Tea"
- //• Втори ред - захар - текст с възможности "Without", "Normal" или "Extra"
- //• Трети ред - брой напитки - цяло число в интервала [1… 50]
- String drink = scanner.nextLine();
- String sugar = scanner.nextLine();
- int countDrinks = Integer.parseInt(scanner.nextLine());
- double price = 0;
- //• При избрана напитка без захар има 35% отстъпка.
- //• При избрана напитка "Espresso" и закупени поне 5 броя, има 25% отстъпка.
- //• При сума надвишава 15 лева, 20% отстъпка от крайната цена,
- //Отстъпките се прилагат в реда на тяхното описване.
- // Без захар Нормално Допълнително захар
- // Еспресо 0.90 лв./бр. 1 лв. /бр. 1.20 лв. /бр.
- // Капучино 1.00 лв. /бр. 1.20 лв. /бр. 1.60 лв. /бр.
- // Чай 0.50 лв. /бр. 0.60 лв. /бр. 0.70 лв. /бр.
- switch (drink) {
- case "Espresso":
- if ("Without".equals(sugar)) {
- price = countDrinks * (0.9 * 0.65);
- if (countDrinks >= 5) {
- price = price * 0.75;
- }
- if (price > 15) {
- price = price * 0.8;
- }
- } else if ("Normal".equals(sugar)) {
- price = countDrinks * 1.0;
- if (price > 15) {
- price = price * 0.8;
- }
- } else {
- price = countDrinks * 1.2;
- if (price > 15) {
- price = price * 0.8;
- }
- }
- break;
- case "Cappuccino":
- if ("Without".equals(sugar)) {
- price = countDrinks * (1.0 * 0.35);
- if (price > 15) {
- price = price * 0.8;
- }
- } else if ("Normal".equals(sugar)) {
- price = countDrinks * 1.2;
- if (price > 15) {
- price = price * 0.8;
- }
- } else {
- price = countDrinks * 1.6;
- if (price > 15) {
- price = price * 0.8;
- }
- }
- break;
- case "Tea":
- if ("Without".equals(sugar)) {
- price = countDrinks * (0.5 * 0.35);
- if (price > 15) {
- price = price * 0.8;
- }
- } else if ("Normal".equals(sugar)) {
- price = countDrinks * 0.6;
- if (price > 15) {
- price = price * 0.8;
- }
- } else {
- price = countDrinks * 0.7;
- if (price > 15) {
- price = price * 0.8;
- }
- }
- break;
- }
- System.out.printf("You bought %d cups of %s for %.2f lv.", countDrinks, drink,price);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement