-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
254 lines (179 loc) · 8.64 KB
/
Copy pathMain.java
File metadata and controls
254 lines (179 loc) · 8.64 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String username;
String password;
while (true) {
System.out.println("\n========== ADMIN LOGIN ==========");
System.out.print("Username: ");
username = sc.nextLine();
System.out.print("Password: ");
password = sc.nextLine();
if (username.equals("admin") && password.equals("admin123")) {
System.out.println("\nLogin Successful!");
break;
}
System.out.println("\nInvalid Username or Password!");
System.out.println("Please try again.\n");
}
EmployeeService service = new EmployeeService();
while (true) {
System.out.println("\n========================================");
System.out.println(" EMPLOYEE MANAGEMENT SYSTEM");
System.out.println("========================================");
System.out.println("1. Add Employee");
System.out.println("2. View Employees");
System.out.println("3. Search Employee by ID");
System.out.println("4. Search Employee by Name");
System.out.println("5. Update Employee");
System.out.println("6. Delete Employee");
System.out.println("7. Dashboard");
System.out.println("8. Export to CSV");
System.out.println("9. Exit");
System.out.print("Enter your choice: ");
int choice = sc.nextInt();
sc.nextLine();
switch (choice) {
case 1:
System.out.print("Enter Employee ID: ");
int id = sc.nextInt();
sc.nextLine();
System.out.print("Enter Employee Name: ");
String name = sc.nextLine();
String department;
while (true) {
System.out.print("Enter Department (IT/HR/Finance/Sales/Marketing): ");
department = sc.nextLine();
if (department.equalsIgnoreCase("IT") ||
department.equalsIgnoreCase("HR") ||
department.equalsIgnoreCase("Finance") ||
department.equalsIgnoreCase("Sales") ||
department.equalsIgnoreCase("Marketing")) {
break;
}
System.out.println("Invalid Department!");
System.out.println("Available Departments:");
System.out.println("IT");
System.out.println("HR");
System.out.println("Finance");
System.out.println("Sales");
System.out.println("Marketing");
}
double salary;
while (true) {
System.out.print("Enter Salary: ");
salary = sc.nextDouble();
sc.nextLine();
if (salary > 0) {
break;
}
System.out.println("Invalid Salary! Salary must be greater than 0.");
}
String phone;
while (true) {
System.out.print("Enter Phone Number: ");
phone = sc.nextLine();
if (phone.matches("[0-9]{10}")) {
break;
}
System.out.println("Invalid Phone Number!");
System.out.println("Phone number must contain exactly 10 digits.");
}
Employee emp = new Employee(id, name, department, salary, phone);
service.addEmployee(emp);
break;
case 2:
service.viewEmployees();
break;
case 3:
System.out.print("Enter Employee ID: ");
int searchId = sc.nextInt();
service.searchEmployee(searchId);
break;
case 4:
System.out.print("Enter Employee Name: ");
String searchName = sc.nextLine();
service.searchEmployeeByName(searchName);
break;
case 5:
System.out.print("Enter Employee ID to Update: ");
int updateId = sc.nextInt();
sc.nextLine();
System.out.print("Enter New Name: ");
String newName = sc.nextLine();
String newDepartment;
while (true) {
System.out.print("Enter New Department (IT/HR/Finance/Sales/Marketing): ");
newDepartment = sc.nextLine();
if (newDepartment.equalsIgnoreCase("IT") ||
newDepartment.equalsIgnoreCase("HR") ||
newDepartment.equalsIgnoreCase("Finance") ||
newDepartment.equalsIgnoreCase("Sales") ||
newDepartment.equalsIgnoreCase("Marketing")) {
break;
}
System.out.println("Invalid Department!");
System.out.println("Available Departments:");
System.out.println("IT");
System.out.println("HR");
System.out.println("Finance");
System.out.println("Sales");
System.out.println("Marketing");
}
double newSalary;
while (true) {
System.out.print("Enter New Salary: ");
newSalary = sc.nextDouble();
sc.nextLine();
if (newSalary > 0) {
break;
}
System.out.println("Invalid Salary! Salary must be greater than 0.");
}
String newPhone;
while (true) {
System.out.print("Enter New Phone: ");
newPhone = sc.nextLine();
if (newPhone.matches("[0-9]{10}")) {
break;
}
System.out.println("Invalid Phone Number!");
System.out.println("Phone number must contain exactly 10 digits.");
}
service.updateEmployee(updateId, newName, newDepartment, newSalary, newPhone);
break;
case 6:
System.out.print("Enter Employee ID to Delete: ");
int deleteId = sc.nextInt();
sc.nextLine();
System.out.print("Are you sure? (yes/no): ");
String confirm = sc.nextLine();
if (confirm.equalsIgnoreCase("yes")) {
service.deleteEmployee(deleteId);
} else {
System.out.println("Delete Cancelled.");
}
break;
case 7:
service.dashboard();
break;
case 8:
service.exportToCSV();
break;
case 9:
System.out.println("\n========================================");
System.out.println(" Thank You for using");
System.out.println(" EMPLOYEE MANAGEMENT SYSTEM");
System.out.println("----------------------------------------");
System.out.println(" Developed by: Thota Usha Laharika");
System.out.println("========================================");
sc.close();
System.exit(0);
break;
default:
System.out.println("Invalid Choice! Please try again.");
}
}
}
}