-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrder.java
More file actions
80 lines (64 loc) · 2.2 KB
/
Order.java
File metadata and controls
80 lines (64 loc) · 2.2 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
/**
* Implementing Order class that handle user new order
*
* Ryan Marvin Sirait
* ETS Edition (14/10/2025)
*/
import java.util.HashMap;
import java.util.Map;
public class Order {
private final Coffee selectedCoffee; //Make new coffee
private String cupSize;
private boolean withMilk;
private int sugarLevel;
public Order(Coffee selectedCoffee) { //Default is regular with no milk and extra sugar
this.selectedCoffee = selectedCoffee;
this.cupSize = "Reguler";
this.withMilk = false;
this.sugarLevel = 0;
}
public void setCustomizations(String cupSize, boolean withMilk, int sugarLevel) {
this.cupSize = cupSize;
this.withMilk = withMilk;
this.sugarLevel = sugarLevel;
}
public double calculateTotalPrice() {
double finalPrice = selectedCoffee.getBasePrice();
if ("Large".equals(this.cupSize)) {
finalPrice += 4000;
}
if (this.withMilk) {
finalPrice += 3000;
}
if (this.sugarLevel == 2) {
finalPrice += 1000;
} else if (this.sugarLevel == 3) {
finalPrice += 1500;
}
return finalPrice;
}
public Map<String, Integer> calculateFinalRecipe() {
Map<String, Integer> finalRecipe = new HashMap<>(selectedCoffee.getBaseRecipe());
if ("Large".equals(this.cupSize)) {
finalRecipe.replaceAll((ingredient, amount) -> (int) (amount * 1.4));
} //Ingredients used
int extraMilkAmount = 40;
if (this.withMilk) {
finalRecipe.put("susu", finalRecipe.getOrDefault("susu", 0) + extraMilkAmount);
finalRecipe.put("kopi", finalRecipe.getOrDefault("kopi", 0) + 2);
} //To balance the coffee flavour add coffee
int extraSugar = switch (this.sugarLevel) {
case 1 -> 2;
case 2 -> 4;
case 3 -> 6;
default -> 0;
};
if (extraSugar > 0) {
finalRecipe.put("gula", finalRecipe.getOrDefault("gula", 0) + extraSugar);
}
return finalRecipe;
}
public Coffee getSelectedCoffee() {
return this.selectedCoffee;
}
}