-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
130 lines (110 loc) · 4.3 KB
/
Copy pathMain.java
File metadata and controls
130 lines (110 loc) · 4.3 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import java.util.Scanner;
// Main entry point for the Asset Management & Analytics System
// Orchestrates authentication and inventory management
public class Main {
private PasswordHasher auth;
private Scanner scanner;
private String currentUser;
private InventoryTracker currentInventory;
public Main() {
auth = new PasswordHasher();
scanner = new Scanner(System.in);
currentUser = null;
currentInventory = null;
}
// Authentication menu - shows until user logs in
public void authMenu() {
while (currentUser == null) {
System.out.println("\n" + "=".repeat(50));
System.out.println(" Asset Management & Analytics System");
System.out.println("=".repeat(50));
System.out.println(" 1. Register");
System.out.println(" 2. Login");
System.out.println(" 3. Exit");
System.out.print(" Choose: ");
String choice = scanner.nextLine().trim();
switch (choice) {
case "1":
System.out.print(" Enter username: ");
String regUsername = scanner.nextLine().trim();
System.out.print(" Enter password: ");
String regPassword = scanner.nextLine();
if (auth.registerUser(regUsername, regPassword)) {
// User registered, stay on auth menu
}
break;
case "2":
System.out.print(" Enter username: ");
String loginUsername = scanner.nextLine().trim();
System.out.print(" Enter password: ");
String loginPassword = scanner.nextLine();
if (auth.loginUser(loginUsername, loginPassword)) {
currentUser = loginUsername;
currentInventory = new InventoryTracker();
}
break;
case "3":
System.out.println("\n Goodbye!");
scanner.close();
System.exit(0);
default:
System.out.println(" [ERROR] Invalid option!");
}
}
}
// User dashboard - main menu after login, delegates to InventoryTracker
public void dashboardMenu() {
while (currentUser != null) {
System.out.println("\n" + "=".repeat(50));
System.out.println(" Dashboard (" + currentUser + ")");
System.out.println("=".repeat(50));
System.out.println(" 1. View Assets");
System.out.println(" 2. Add Asset");
System.out.println(" 3. Update Asset Quantity");
System.out.println(" 4. Edit Asset");
System.out.println(" 5. View Stats");
System.out.println(" 6. Sort & View Assets");
System.out.println(" 7. Logout");
System.out.print(" Choose: ");
String choice = scanner.nextLine().trim();
switch (choice) {
case "1":
currentInventory.viewAssets();
break;
case "2":
currentInventory.addAsset(scanner);
break;
case "3":
currentInventory.updateAssetQty(scanner);
break;
case "4":
currentInventory.editAsset(scanner);
break;
case "5":
currentInventory.showStats();
break;
case "6":
currentInventory.sortAndView(scanner);
break;
case "7":
System.out.println(" [INFO] Logged out!");
currentUser = null;
currentInventory = null;
break;
default:
System.out.println(" [ERROR] Invalid option!");
}
}
}
// Main control flow - loop between auth and dashboard menus
public void run() {
while (true) {
authMenu();
dashboardMenu();
}
}
public static void main(String[] args) {
Main app = new Main();
app.run();
}
}