-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoffeeMachine.java
More file actions
88 lines (62 loc) · 2.06 KB
/
Copy pathCoffeeMachine.java
File metadata and controls
88 lines (62 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package PBExams;
import java.util.Scanner;
public class CoffeeMachine {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String drink = scanner.nextLine();
String sugar = scanner.nextLine();
int quantity = Integer.parseInt(scanner.nextLine());
double price = 0;
switch(drink){
case "Espresso":
switch (sugar){
case "Without":
price = quantity * 0.90;
break;
case "Normal":
price = quantity * 1.00;
break;
case "Extra":
price = quantity * 1.20;
break;
}
break;
case "Cappuccino":
switch (sugar){
case "Without":
price = quantity * 1.00;
break;
case "Normal":
price = quantity * 1.20;
break;
case "Extra":
price = quantity * 1.60;
break;
}
break;
case "Tea":
switch (sugar){
case "Without":
price = quantity * 0.50;
break;
case "Normal":
price = quantity * 0.60;
break;
case "Extra":
price = quantity * 0.70;
break;
}
break;
}
if(sugar.equals("Without")){
price = price - price * 0.35;
}
if(drink.equals("Espresso") && quantity >= 5){
price = price - price * 0.25;
}
if(price > 15){
price = price - price * 0.20;
}
System.out.printf("You bought %d cups of %s for %.2f lv.",quantity,drink,price);
}
}