update,
This commit is contained in:
25
_resources/it114105/itp4510/Lab01/Lab1.2/q1/Food.java
Normal file
25
_resources/it114105/itp4510/Lab01/Lab1.2/q1/Food.java
Normal file
@@ -0,0 +1,25 @@
|
||||
public class Food {
|
||||
protected String name;
|
||||
protected int price;
|
||||
|
||||
public Food() {
|
||||
name = null;
|
||||
price = 0;
|
||||
}
|
||||
|
||||
public Food(String name, int price) {
|
||||
this.name = name;
|
||||
setPrice(price);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "name=" + name + ", price=" + price;
|
||||
}
|
||||
|
||||
public void setPrice(int price) {
|
||||
if (price >= 0)
|
||||
this.price = price;
|
||||
else
|
||||
this.price = 0;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user