-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventoryManager.java
More file actions
76 lines (67 loc) · 2.16 KB
/
Copy pathInventoryManager.java
File metadata and controls
76 lines (67 loc) · 2.16 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
import java.util.ArrayList;
import java.util.List;
public class InventoryManager {
private List<Product> products = new ArrayList<>();
public void addProduct(Product product) {
products.add(product);
System.out.println("✅ Product added successfully!");
if (product.isLowStock()) {
System.out.println("🚨 ALERT: This product is already low on stock!");
}
}
public void viewProducts() {
if (products.isEmpty()) {
System.out.println("⚠ Inventory is empty.");
return;
}
for (Product p : products) {
System.out.println(p);
}
}
public Product searchProduct(int id) {
for (Product p : products) {
if (p.getId() == id) return p;
}
return null;
}
public void updateQuantity(int id, int qty) {
Product p = searchProduct(id);
if (p != null) {
p.setQuantity(qty);
System.out.println("🔄 Quantity updated!");
if (p.isLowStock()) {
System.out.println("🚨 ALERT: Stock is below minimum level!");
}
} else {
System.out.println("❌ Product not found.");
}
}
public void deleteProduct(int id) {
Product p = searchProduct(id);
if (p != null) {
products.remove(p);
System.out.println("🗑 Product removed!");
} else {
System.out.println("❌ Product not found.");
}
}
public void totalInventoryValue() {
double total = 0;
for (Product p : products) {
total += p.getTotalValue();
}
System.out.println("💰 Total Inventory Value: ₹" + total);
}
public void showLowStockProducts() {
boolean found = false;
for (Product p : products) {
if (p.isLowStock()) {
System.out.println("⚠ LOW STOCK ALERT → " + p);
found = true;
}
}
if (!found) {
System.out.println("✅ No low stock products.");
}
}
}