-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStoreInventoryList.java
More file actions
84 lines (74 loc) · 2.59 KB
/
StoreInventoryList.java
File metadata and controls
84 lines (74 loc) · 2.59 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
import java.util.ArrayList;
import java.util.List;
public class StoreInventoryList {
private List<Product> products;
// Constructor
public StoreInventoryList() {
this.products = new ArrayList<>();
// Optionally add predefined products
}
// Add a product to the inventory
public void addProduct(Product product) {
products.add(product);
System.out.println("The product was added successfully.");
}
// Remove a product by ID
public void removeProduct(int productID) {
Product product = findProductByID(productID);
if (product != null) {
products.remove(product);
System.out.println("The product was removed successfully.");
} else {
System.out.println("The product with ID " + productID + " has not been found.");
}
}
// Find a product by ID
private Product findProductByID(int productID) {
for (Product product : products) {
if (product.getProductID() == productID) {
return product;
}
}
return null;
}
// Add stock to a product
public void addStockToProduct(int productID, int quantity) {
Product product = findProductByID(productID);
if (product != null) {
product.addStock(quantity);
System.out.println("The stock has added successfully.");
} else {
System.out.println("Sorry, the product with ID " + productID + " has not been found.");
}
}
// Remove stock from a product
public void removeStockFromProduct(int productID, int quantity) {
Product product = findProductByID(productID);
if (product != null) {
product.removeStock(quantity);
System.out.println("The stock has been removed successfully.");
} else {
System.out.println("Sorry, product with ID " + productID + " has not been found.");
}
}
// Display all products
public void displayAllProducts() {
if (products.isEmpty()) {
System.out.println("The inventory is empty.");
} else {
for (Product product : products) {
product.displayProductInfo();
System.out.println("--------------------------------");
}
}
}
// Generate a detailed inventory report
public void generateReport() {
System.out.println("Full Inventory Report:");
displayAllProducts();
}
// Get the number of products in the inventory
public int getProductCount() {
return products.size();
}
}