-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStoreInventory.java
More file actions
63 lines (54 loc) · 2.51 KB
/
StoreInventory.java
File metadata and controls
63 lines (54 loc) · 2.51 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
public class StoreInventory {
// Product instances
private Product product1;
private Product product2;
private Product product3;
private Product product4;
public StoreInventory(Product product1, Product product2, Product product3, Product product4) {
this.product1 = product1;
this.product2 = product2;
this.product3 = product3;
this.product4 = product4;
}
public void addStockToProduct(int productID, int quantity) {
// This ensures we are using the right product specific method.
if (this.product1.getProductID() == productID) {
this.product1.addStock(quantity);
} else if (this.product2.getProductID() == productID) {
this.product2.addStock(quantity);
} else if (this.product3.getProductID() == productID) {
this.product3.addStock(quantity);
} else if (this.product4.getProductID() == productID) {
this.product4.addStock(quantity);
} else {
System.out.println("Sorry it seems your item was not found. \n Double check the product ID and try again!");
}
}
public void removeStockFromProduct(int productID, int quantity) {
// This ensures we are using the right product specific method.
if (this.product1.getProductID() == productID) {
this.product1.removeStock(quantity);
} else if (this.product2.getProductID() == productID) {
this.product2.removeStock(quantity);
} else if (this.product3.getProductID() == productID) {
this.product3.removeStock(quantity);
} else if (this.product4.getProductID() == productID) {
this.product4.removeStock(quantity);
} else {
System.out.println("Sorry it seems your item was not found. \n Double check the product ID and try again!");
}
}
public void generateReport() {
// This displays all the individual product specific info
System.out.println("Full details and stock information of products:");
System.out.println("_____________________________");
this.product1.displayProductInfo();
System.out.println("_____________________________");
this.product2.displayProductInfo();
System.out.println("_____________________________");
this.product3.displayProductInfo();
System.out.println("_____________________________");
this.product4.displayProductInfo();
System.out.println("_____________________________");
}
}