-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCookie.java
More file actions
82 lines (75 loc) · 1.85 KB
/
Cookie.java
File metadata and controls
82 lines (75 loc) · 1.85 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
/**
* @author XiuNhon
*
* subclass Cookie inherited from class DessertItem, create getter
* methods for Cookie, override abstract method getCost to calculate
* price per dozen, override toString accordingly
*/
public class Cookie extends DessertItem {
private int numOfCookie;
private double pricePerDozen;
/**
* Null constructor for Cookie class inherited from DessertItem class
*/
public Cookie() {
super();
numOfCookie = 0;
pricePerDozen = 0;
}
/**
* overloaded constructor for Cookie class inherited from DessertItem class add
* numOfCookie and pricePerDozen parameter
*
* @param name, calories
*/
public Cookie(String name, int calories) {
super(name, calories);
this.name = name + "(Cookie)";
numOfCookie = 0;
pricePerDozen = 0;
}
/**
* @param name, calories, number, price
*/
public Cookie(String name, int calories, int number, double price) {
super(name, calories);
this.name = name + "(Cookie)";
this.numOfCookie = number;
pricePerDozen = price;
}
/**
* getters
*/
/**
*
* @return number of cookies
*/
public int getNumOfCookie() {
return numOfCookie;
}
/**
*
* @return unit price per dozen
*/
public double getPricePerDozen() {
return pricePerDozen;
}
/**
* @override abstract getCost from DesserItem class
* @return cost for cookies calculated with price per dozen
*/
public double getCost() {
double cost = numOfCookie * (pricePerDozen / 12);
return Math.round(cost);
}
/**
* @override toString()
* @return new string
*/
public String toString() {
return getNumOfCookie() + " @ " + getPricePerDozen() / 100 + " /dz." + "\n"
+ String.format("%-30s %5.2f", name, getCost() / 100)
// + "\n\n" + name + " calories: " + getCalories()
;
}
}// end of class