-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKopi.java
35 lines (28 loc) · 878 Bytes
/
Kopi.java
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
package cafe_kasir;
import javax.swing.JOptionPane;
public class Kopi extends Minuman {
private boolean milk;
public Kopi(String size, int amount, Cafe_kasir lbl) {
super(size, amount);
milk = JOptionPane.showConfirmDialog(lbl, "Would you like milk?", "Milk", JOptionPane.YES_NO_OPTION) == 0;
double basePrice;
double milkPrice = 0.0;
basePrice = switch (size) {
case "Small" -> 10000;
case "Medium" -> 11000;
default -> 12000;
};
if (milk) {
milkPrice = 2000;
}
setPrice(basePrice + milkPrice);
}
@Override
public String toString() {
if (milk) {
return super.toString() + "Coffee with milk";
} else {
return super.toString() + "Coffee";
}
}
}