-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolymorphismPerishable.java
More file actions
43 lines (37 loc) · 1.38 KB
/
PolymorphismPerishable.java
File metadata and controls
43 lines (37 loc) · 1.38 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
public class PolymorphismPerishable extends Encapsulation{
private String product;
private String expirationDate;
private static final int MAX_QUANTITY = 100;
public PolymorphismPerishable(String product, String expirationDate) {
super(product, product, MAX_QUANTITY, MAX_QUANTITY);
this.product = product;
this.expirationDate = expirationDate;
}
public String getExpirationDate() {
return expirationDate;
}
public void setExpirationDate(String expirationDate) {
this.expirationDate = expirationDate;
}
public String getProduct() {
return product;
}
public void setProduct(String product) {
this.product = product;
}
public static int getMaxQuantity() {
return MAX_QUANTITY;
}
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());
}
}
}