-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPizza.java
More file actions
94 lines (76 loc) · 2.04 KB
/
Pizza.java
File metadata and controls
94 lines (76 loc) · 2.04 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
89
90
91
92
93
94
import java.util.Arrays;
public class Pizza {
// Attributes Pizzas Have
// Access Modifiers
private String type;
private String[] toppings;
private String size;
private int slices;
// Constructor
public Pizza(String type, String[] toppings, String size, int slices) {
this.type = type;
this.toppings = toppings;
this.size = size;
this.slices = slices;
}
// Method Overloading
public Pizza(String type, String[] toppings) {
this.type = type;
this.toppings = toppings;
this.size = "XL";
this.slices = 16;
}
// Getters
public String getType() {
return this.type;
}
public String[] getToppings() {
return this.toppings;
}
public String getSize() {
return this.size;
}
public int getSlices() {
return this.slices;
}
// Setters
public void setType(String type) {
if (type.equals("")) {
System.out.println("Type Not Recgoznied");
return;
}
this.type = type;
}
public void setToppings(String[] toppings) {
this.toppings = toppings;
}
public void setSize(String size) {
this.size = size;
}
public void setSlices(int slices) {
this.slices = slices;
}
// Methods
// Display Pizza
public String displayPizza() {
return "This is a " + this.type + " Pizza " + "with " + Arrays.toString(this.toppings);
}
public int eatSlice(int slices) {
System.out.println("You have eaten " + slices + " slices of " + this.type + " pizza");
this.slices = this.slices - slices;
return this.slices;
}
// Overloaded Method
public void eatSlice() {
this.slices = this.slices - 1;
}
public static void advertise() {
System.out.println("Come To James and Camerons for the best pizza around! Instructor Matt eats free");
}
// Method interacting with Other Object
public void pizzaFight(Pizza otherPizza) {
int otherSlices = otherPizza.getSlices();
otherPizza.setSlices(otherSlices -= 1);
System.out.println(this.type + " knocked " + otherPizza.getType() + " block off and they are missing one slice");
}
}