-
Notifications
You must be signed in to change notification settings - Fork 0
/
IceCream.java
56 lines (51 loc) · 1.24 KB
/
IceCream.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
/**
* @author XiuNhon
*
* subclass IceCream inherited from class DessertItem, create getter
* methods for IceCream, override abstract method getCost, override
* toString accordingly
*/
public class IceCream extends DessertItem {
protected double cost;
/**
* Null constructor for IceCream class inherited from DessertItem class
*/
public IceCream() {
super();
}
/**
* overloaded constructor for IceCream class inherited from DessertItem class
*
* @param name, calories
*/
public IceCream(String name, int calories) {
super(name, calories);
this.name = name + "(IceCream)";
}
/**
* add cost parameter
*
* @param name, calories, cost
*/
public IceCream(String name, int calories, double cost) {
super(name, calories);
this.name = name + "(IceCream)";
this.cost = cost;
}
/**
* @override abstract getCost from DesserItem class
* @return cost of IceCream
*/
public double getCost() {
return Math.round(cost);
}
/**
* @override toString
* @return new string
*/
public String toString() {
return String.format("%-30s %5.2f", name, getCost() / 100)
// + "\n\n" + name + " calories: " + getCalories()
;
}
}// end of class