-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTaco.java
More file actions
72 lines (67 loc) · 1.62 KB
/
Taco.java
File metadata and controls
72 lines (67 loc) · 1.62 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
public class Taco {
//separated front end
//separated taco manager
//always want to keep front eend & back end separated
private String name;
private String maker;
private double price;
private int rating; //0-5
public Taco() {
this.name=this.maker="No name yet";
this.price=0.0;
this.rating=0;
}
public Taco(String aName, String aMaker, double aPrice, int aRating)
{
//TODO call mutators
}
//auto-generated by right-clicking, source, generate getters & setters
//add error-checking
public String getName() {
return name;
}
public void setName(String name) {
//can have parameters & attributes with the same name in Java
//differentiate by using this. for the attribute
//this is the old style; Java hasn't been updated; new convention is aName for the parameter
this.name = name;
}
public String getMaker() {
return maker;
}
public void setMaker(String maker) {
this.maker = maker;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
if (price >= 0.0)
{
this.price = price;
}
}
public int getRating() {
return rating;
}
public void setRating(int rating) {
if (rating <= 5 && rating >= 0)
{
this.rating = rating;
}
}
@Override
//auto generated
public String toString() {
return "Taco [name=" + name + ", maker=" + maker + ", price=" + price + ", rating=" + rating + "]";
}
//auto generated equals is messy
public boolean equals(Taco aTaco)
{
return aTaco != null &&
this.name.equals(aTaco.getName()) &&
this.maker.equals(aTaco.getMaker()) &&
this.price == aTaco.getPrice() &&
this.rating == aTaco.getRating();
}
}