-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinventorySystem.java
More file actions
33 lines (27 loc) · 1012 Bytes
/
inventorySystem.java
File metadata and controls
33 lines (27 loc) · 1012 Bytes
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
import java.util.HashMap;
import java.util.Map;
class inventorySystem{
Map<String,Integer> inventory =new HashMap<>();
public void addOrUpdateStock(String inv,int quantity){
inventory.put(inv,inventory.getOrDefault(inv, 0)+quantity);
/*if (!inventory.containsKey(inv))
inventory.put(inv,quantity);
else
inventory.put(inv,inventory.get(inv)+quantity);*/
}
public int getStock(String inv){
return inventory.get(inv);
}
public void printInventory(){
inventory.forEach((item,quantity)->System.out.println("Item: "+item+" Qunatity: "+quantity));
}
public static void main(String args[]){
inventorySystem inv=new inventorySystem();
inv.addOrUpdateStock("Pencil",3);
inv.addOrUpdateStock("Marker", 4);
inv.addOrUpdateStock("Pen", 10);
inv.addOrUpdateStock("Pencil", 6);
inv.getStock("Pencil");
inv.printInventory();
}
}