-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackagedProduct.java
More file actions
49 lines (39 loc) · 1.33 KB
/
PackagedProduct.java
File metadata and controls
49 lines (39 loc) · 1.33 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
package onlinestore;
public class PackagedProduct extends Product {
double packagedPrice;
//constructor
public PackagedProduct(String name, double price, eCategory category, double packagedPrice)
throws StringEmptyNullException, NegativeNumException{
super(name, price, category);
setWrappedPrice(packagedPrice);
}
//copy constructor
public PackagedProduct(PackagedProduct other) {
super(other);
this.packagedPrice = other.packagedPrice;
}
public double getPackagedPrice() {
return packagedPrice;
}
public void setWrappedPrice(double packagedPrice) throws NegativeNumException{
if (packagedPrice < 0) {
throw new NegativeNumException("Package price");
}
this.packagedPrice = packagedPrice;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof PackagedProduct packagedProduct)) {
return false;
}
return super.equals(other) && this.packagedPrice == packagedProduct.packagedPrice;
}
@Override
public PackagedProduct clone() throws CloneNotSupportedException {
return (PackagedProduct)super.clone();
}
@Override
public String toString() {
return super.toString() + ", Package price: " + packagedPrice + "$";
}
}