-
Notifications
You must be signed in to change notification settings - Fork 0
/
Coffee.java
77 lines (62 loc) · 1.59 KB
/
Coffee.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
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
public class Coffee extends Beverage{
private boolean extraSyrup;
private final double SHOT_COST = .5;
private boolean extraShot;
private final double SYRUP_COST = .5;
public Coffee(String n, SIZE s, boolean shot, boolean syrup) {
super(n, TYPE.COFFEE, s);
extraShot = shot;
extraSyrup = syrup;
}
public String toString() {
String s = getBevName() +", " +getSize();
if (extraShot) {
s += " Extra shot";
}
if (extraSyrup) {
s += " Extra syrup";
}
s += ", $" +calcPrice();
return s;
}
public double calcPrice() {
double price = super.getBasePrice();
if (super.getSize() == SIZE.MEDIUM) {
price += super.getSizePrice();
}
else if (super.getSize() == SIZE.LARGE) {
price += 2 * super.getSizePrice();
}
if (extraShot) {
price += SHOT_COST;
}
if (extraSyrup) {
price += SYRUP_COST;
}
return price;
}
public boolean equals(Coffee c) {
if (super.equals(c) && extraShot==c.getExtraShot() && extraSyrup==c.getExtraSyrup()) {
return true;}
else {
return false;
}
}
public double getShotCost() {
return SHOT_COST;
}
public double getSyrupCost() {
return SYRUP_COST;
}public boolean getExtraShot() {
return extraShot;
}
public boolean getExtraSyrup() {
return extraSyrup;
}
public void setExtraShot(boolean shot) {
extraShot = shot;
}
public void setExtraSyrup(boolean syrup) {
extraSyrup = syrup;
}
}