-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSundae.java
More file actions
90 lines (82 loc) · 2.02 KB
/
Sundae.java
File metadata and controls
90 lines (82 loc) · 2.02 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
/**
* @author XiuNhon
*
* subclass Sundae inherited from class IceCream, create getter methods
* for Sundae, override abstract method getCost to calculate IceCream
* cost + toppingCost, override toString accordingly
*/
public class Sundae extends IceCream {
private String topping;
private double toppingCost;
/**
* Null constructor for Sundae class inherited from IceCream class
*/
public Sundae() {
super();
}
/**
* overloaded constructor for Sundae class inherited from IceCream class
*
* @param name, calories
*/
public Sundae(String name, int calories) {
super(name, calories);
this.name = name + "(Sundae)";
topping = "";
}
/**
* add cost parameter
*
* @param name, calories, cost
*/
public Sundae(String name, int calories, double cost) {
super(name, calories, cost);
this.name = name + "(Sundae)";
topping = "";
this.cost = cost;
}
/**
* add topping's variables
*
* @param name,calories,cost,topping,toppingCost
*/
public Sundae(String name, int calories, double cost, String topping, double toppingCost) {
super(name, calories, cost);
this.name = name + "(Sundae)";
this.topping = topping + "(Topping)";
this.toppingCost = toppingCost;
}
/**
* getter
*
* @return topping name of Sundae
*/
public String getTopping() {
return topping;
}
/**
* getter
*
* @return topping cost of Sundae
*/
public double getToppingCost() {
return toppingCost;
}
/**
* @override abstract getCost from DesserItem class
* @return cost of Sundae, calculated from icecream cost + topping cost
*/
public double getCost() {
return Math.round(cost + toppingCost);
}
/**
* @override toString
* @return new string
*/
public String toString() {
return name + " with\n"
+ String.format("%-30s %5.2f", getTopping() + "+@ " + getToppingCost() / 100, getCost() / 100)
// + "\n\n" + name + " calories: " + getCalories()
;
}
}// end of class