-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserManagementSystem.java
More file actions
92 lines (84 loc) · 3.32 KB
/
UserManagementSystem.java
File metadata and controls
92 lines (84 loc) · 3.32 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
import java.util.Scanner;
public class UserManagementSystem {
private static UserService userService;
private static Scanner scanner;
private static User currentUser;
public static void main(String[] args) {
userService = new UserService();
scanner = new Scanner(System.in);
currentUser = null;
System.out.println("=====================================");
System.out.println(" USER & PROFILE MANAGEMENT SYSTEM ");
System.out.println("=====================================");
while (true) {
displayMainMenu();
int choice = getIntInput("Enter your choice: ");
switch (choice) {
case 1:
userService.registerUser();
break;
case 2:
currentUser = userService.loginUser();
break;
case 3:
if (currentUser != null) {
userService.updateProfile(currentUser);
} else {
System.out.println("✗ Please login first!");
}
break;
case 4:
userService.searchUserByEmail();
break;
case 5:
userService.displayAllUsers();
break;
case 6:
if (currentUser != null) {
System.out.println("✓ Logged out successfully!");
currentUser = null;
} else {
System.out.println("No user is currently logged in.");
}
break;
case 7:
System.out.println("Thank you for using the system!");
System.out.println("Goodbye!");
scanner.close();
System.exit(0);
break;
default:
System.out.println("✗ Invalid choice! Please try again.");
}
System.out.println("\nPress Enter to continue...");
scanner.nextLine();
}
}
private static void displayMainMenu() {
System.out.println("\n=====================================");
if (currentUser != null) {
System.out.println(" Logged in as: " + currentUser.getName());
} else {
System.out.println(" Status: Not Logged In");
}
System.out.println("=====================================");
System.out.println("1. Register New User");
System.out.println("2. Login");
System.out.println("3. Update My Profile");
System.out.println("4. Search User Profile");
System.out.println("5. View All Users");
System.out.println("6. Logout");
System.out.println("7. Exit");
System.out.println("=====================================");
}
private static int getIntInput(String prompt) {
System.out.print(prompt);
while (!scanner.hasNextInt()) {
System.out.print("Invalid input! " + prompt);
scanner.next();
}
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
return choice;
}
}