-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5OnlineShoppingManager.java
More file actions
47 lines (40 loc) · 1.31 KB
/
Copy path5OnlineShoppingManager.java
File metadata and controls
47 lines (40 loc) · 1.31 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
import java.util.Vector;
public class 5OnlineShoppingManager {
Vector<Product> list = new Vector<>();
public void addEle(String name, int quantity, String type) {
Product p = new Product(name, quantity, type);
list.add(p);
}
public void remove(String name) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i).name.equals(name)) {
list.remove(i);
break;
}
}
}
public void display() {
System.out.println("Inventory:");
for (Product product : list) {
System.out.println("Name: " + product.name + " | Quantity: " + product.quantity + " | Type: " + product.type);
}
}
public static void main(String[] args) {
OnlineShoppingManager manager = new OnlineShoppingManager();
manager.addEle("milk", 8, "dairy");
manager.addEle("aata", 5, "grocery");
manager.display();
manager.remove("milk");
manager.display();
}
public static class Product { // Changed Product1 to Product and made it static
String name;
int quantity;
String type;
Product(String name, int quantity, String type) {
this.name = name;
this.quantity = quantity;
this.type = type;
}
}
}