-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProduct.java
More file actions
51 lines (47 loc) · 1.31 KB
/
Product.java
File metadata and controls
51 lines (47 loc) · 1.31 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
public abstract class Product implements Comparable<Product> {
private final double price;
private int stockQuantity;
private int soldQuantity;
private int totalRevenue = 0;
private int cartQuantity;
public Product (double InitPrice, int InitStockQuantity) {
price = InitPrice;
stockQuantity = InitStockQuantity;
soldQuantity = 0;
cartQuantity = 0;
}
//get methods
public double getPrice() {
return price;
}
public int getSoldQuantity() {
return soldQuantity;
}
public int getStockQuantity() {
return stockQuantity;
}
public int getCartQuantity() {
return cartQuantity;
}
public int getTotalRevenue() {return totalRevenue;}
//set method
public void setCartQuantity(int cartQuantity) {
this.cartQuantity = cartQuantity;
}
//adjust stock and sold quantities and update the products own revenue
public void sellUnits(int amount) {
if (stockQuantity >= amount) {
stockQuantity -= amount;
soldQuantity += amount;
totalRevenue += (amount * price);
}
}
@Override
public int hashCode() {
return -1;
}
@Override
public int compareTo(Product o) {
return o.getSoldQuantity() - soldQuantity;
}
}