-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritancePerishable.java
More file actions
50 lines (45 loc) · 1.84 KB
/
InheritancePerishable.java
File metadata and controls
50 lines (45 loc) · 1.84 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
public class InheritancePerishable(String productId, String productName, int quantity, double price, String expirationDate) {
super(productId, productName, quantity, price);
this.expirationDate = expirationDate;
}
public String getExpirationDate() {
return expirationDate;
}
public void setExpirationDate(String expirationDate) {
this.expirationDate = expirationDate;
}
public void updateStock(int amount) {
if (amount < 0 && getQuantity() + amount < 0) {
System.out.println("Insufficient stock for product " + getProductName() + ".");
}
int newQuantity = getQuantity() + amount;
if (newQuantity > MAX_QUANTITY) {
System.out.println("Cannot exceed maximum quantity of " + MAX_QUANTITY + " for perishable products.");
} else {
setQuantity(newQuantity);
System.out.println("Stock updated. New quantity: " + getQuantity());
}
}
public InheritanceNonPerishable(String productId, String productName, int quantity, double price, int shelfLife) {
super(productId, productName, quantity, price);
this.shelfLife = shelfLife;
}
public int getShelfLife() {
return shelfLife;
}
public void setShelfLife(int shelfLife) {
this.shelfLife = shelfLife;
}
public void updateStock(int amount) {
if (amount < 0 && getQuantity() + amount < 0) {
System.out.println("Insufficient stock for product " + getProductName() + ".");
}
int newQuantity = getQuantity() + amount;
if (newQuantity > MAX_QUANTITY) {
System.out.println("Cannot exceed maximum quantity of " + MAX_QUANTITY + " for perishable products.");
} else {
setQuantity(newQuantity);
System.out.println("Stock updated. New quantity: " + getQuantity());
}
}
}