-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProduct.java
More file actions
84 lines (67 loc) · 2.02 KB
/
Product.java
File metadata and controls
84 lines (67 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
package onlinestore;
public class Product implements Cloneable {
protected String name;
protected double price;
protected static int counter;
protected int serialNumber;
protected eCategory category;
// Constructor
public Product(String name, double price, eCategory category) throws StringEmptyNullException,
NegativeNumException{
setName(name);
setPrice(price);
this.serialNumber = ++counter;
this.category = category;
}
// Copy Constructor
public Product(Product other) {
this.name = other.name;
this.price = other.price;
this.serialNumber = other.serialNumber;
this.category = other.category;
}
public String getName() {
return name;
}
public void setName(String name) throws StringEmptyNullException {
if (name == null || name.isEmpty()) {
throw new StringEmptyNullException("name");
}
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) throws NegativeNumException {
if (price < 0) {
throw new NegativeNumException("price");
}
this.price = price;
}
public eCategory getCategory() {
return category;
}
public int getSerialNumber() {
return serialNumber;
}
public static int getCounter() {
return counter;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof Product)) {
return false;
}
Product product = (Product)other;
return product.name.equals(this.name) && product.price == this.price && product.category == this.category &&
product.serialNumber == this.serialNumber;
}
@Override
public Product clone() throws CloneNotSupportedException {
return (Product)super.clone();
}
@Override
public String toString() {
return name + ", " + price + "$, " + "Serial Num: " + serialNumber;
}
}