-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventoryApp.java
More file actions
61 lines (52 loc) · 1.82 KB
/
InventoryApp.java
File metadata and controls
61 lines (52 loc) · 1.82 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
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class InventoryApp {
public static HashMap<String, Tool> invList = new HashMap<>();
public static Scanner read = new Scanner(System.in);
public static void main(String[] args) {
addTool("T001", "Wrench", 2, 10.00);
addTool("T002", "Knife", 3, 8.50);
addTool("T003", "Scissor", 2, 2.50);
addTool("T004", "Hammer", 1, 7.00);
addTool("T005", "Saw", 1, 13.25);
displayInventory();
removeTool("T002");
removeTool("T003");
displayInventory();
}
public static void addTool(String pid, String pname, Integer qty, Double uprice) {
if (invList.containsKey(pid)) {
System.out.println("A product already exists under this code..!");
System.out.print("Do ypu want to update the product ? : ");
if (read.next().equalsIgnoreCase("yes")) {
invList.put(pid, new Tool(pname, qty, uprice));
System.out.println("Product updated successfully");
}
else if (read.next().equalsIgnoreCase("no")) {
return;
}
else {
return;
}
}
invList.put(pid, new Tool(pname, qty, uprice));
System.out.println("Product added successfully");
}
public static void removeTool(String pid) {
if (invList.containsKey(pid)) {
invList.remove(pid);
System.out.println("Product removed successfully");
System.out.println();
}
}
public static void displayInventory() {
for (Map.Entry<String, Tool> tool : invList.entrySet()) {
System.out.println("Product ID : " + tool.getKey());
System.out.println("\tProduct Name : " + tool.getValue().getProductName());
System.out.println("\tProduct Quantity : " + tool.getValue().getQuantity());
System.out.println("\tProduct Unit Price : " + tool.getValue().getUnitPrice());
System.out.println();
}
}
}