-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBurger.java
82 lines (81 loc) · 2.27 KB
/
Burger.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
78
79
80
81
82
public class Burger {
private boolean ketchup;
private boolean lettuce;
private boolean tomato;
private boolean cheese;
private int patties;
public Burger() {
ketchup = false;
lettuce = false;
tomato = false;
cheese = false;
patties = 1;
}
public Burger(boolean ketchup, boolean lettuce, boolean tomato, boolean cheese, int patties) {
this.ketchup = ketchup;
this.lettuce = lettuce;
this.tomato = tomato;
this.cheese = cheese;
this.patties = patties;
}
public boolean getKetchup() {
return ketchup;
}
public void setKetchup(boolean ketchup) {
this.ketchup = ketchup;
}
public boolean getLettuce() {
return lettuce;
}
public void setLettuce(boolean lettuce) {
this.lettuce = lettuce;
}
public boolean getTomato() {
return tomato;
}
public void setTomato(boolean tomato) {
this.tomato = tomato;
}
public boolean getCheese() {
return cheese;
}
public void setCheese(boolean cheese) {
this.cheese = cheese;
}
public int getPatties() {
return patties;
}
public void setPatties(int patties) {
if (patties > 3) {
throw new IllegalArgumentException("Too many patties");
}
this.patties = patties;
}
public float getPrice() {
float price = 4;
if (tomato) {
price += .25;
}
if (cheese) {
price += .50;
}
price += patties - 1;
return price;
}
public String toString() {
return "Burger with " + patties + (patties > 1 ? " patties" : " patty") + (tomato ? ", tomato" : "") + (cheese ? ", cheese" : "") + (ketchup ? ", ketchup" : "") + (lettuce ? ", lettuce" : "");
}
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (!(obj instanceof Burger)) {
return false;
}
Burger burger = (Burger) obj;
return burger.getKetchup() == ketchup && burger.getLettuce() == lettuce && burger.getTomato() == tomato && burger.getCheese() == cheese && burger.getPatties() == patties;
}
}