-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployeeManagementSystem.java
More file actions
561 lines (490 loc) · 19.4 KB
/
Copy pathEmployeeManagementSystem.java
File metadata and controls
561 lines (490 loc) · 19.4 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
import java.util.*;
public class EmployeeManagementSystem {
static Scanner scanner = new Scanner(System.in);
static Map<Integer, Employee> employees = new HashMap<>();
static Map<Integer, Department> departments = new HashMap<>();
static int employeeIdCounter = 1;
static int departmentIdCounter = 1;
public static void main(String[] args) {
while (true) {
System.out.println("\nMain Menu:");
System.out.println("1. Employee Management");
System.out.println("2. Hierarchy Management");
System.out.println("3. Department Management");
System.out.println("4. Performance Tracking");
System.out.println("5. Security and Access Control");
System.out.println("6. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine(); // consume newline
switch (choice) {
case 1:
employeeManagementMenu();
break;
case 2:
hierarchyManagementMenu();
break;
case 3:
departmentManagementMenu();
break;
case 4:
performanceTrackingMenu();
break;
case 5:
securityMenu();
break;
case 6:
System.out.println("Exiting...");
System.exit(0);
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
private static void employeeManagementMenu() {
System.out.println("\nEmployee Management Menu:");
System.out.println("1. Add new employee");
System.out.println("2. Remove employee");
System.out.println("3. Update employee information");
System.out.println("4. Change employee department");
System.out.println("5. Promote or demote employee");
System.out.println("6. Back to main menu");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine(); // consume newline
switch (choice) {
case 1:
addEmployee();
break;
case 2:
removeEmployee();
break;
case 3:
updateEmployeeInformation();
break;
case 4:
changeEmployeeDepartment();
break;
case 5:
promoteOrDemoteEmployee();
break;
case 6:
return; // Back to main menu
default:
System.out.println("Invalid choice. Please try again.");
}
}
private static void addEmployee() {
System.out.print("Enter employee name: ");
String name = scanner.nextLine();
System.out.print("Enter employee position: ");
String position = scanner.nextLine();
System.out.print("Enter employee department ID: ");
int departmentId = scanner.nextInt();
System.out.print("Enter employee salary: ");
double salary = scanner.nextDouble();
scanner.nextLine(); // consume newline
Department department = departments.get(departmentId);
if (department == null) {
System.out.println("Invalid department ID.");
return;
}
Employee newEmployee = new Employee(name, employeeIdCounter++, position, department.getName(), salary);
employees.put(newEmployee.getId(), newEmployee);
department.addEmployee(newEmployee);
System.out.println("Employee added successfully.");
}
private static void removeEmployee() {
System.out.print("Enter employee ID to remove: ");
int id = scanner.nextInt();
scanner.nextLine(); // consume newline
Employee employee = employees.get(id);
if (employee != null) {
employees.remove(id);
Department department = departments.get(employee.getDepartmentId());
if (department != null) {
department.removeEmployee(employee);
}
System.out.println("Employee removed successfully.");
} else {
System.out.println("Employee not found.");
}
}
private static void updateEmployeeInformation() {
System.out.print("Enter employee ID to update: ");
int id = scanner.nextInt();
scanner.nextLine(); // consume newline
Employee employee = employees.get(id);
if (employee != null) {
System.out.print("Enter new position (leave blank to keep unchanged): ");
String position = scanner.nextLine();
if (!position.isEmpty()) {
employee.setPosition(position);
}
System.out.print("Enter new salary (leave blank to keep unchanged): ");
String salaryStr = scanner.nextLine();
if (!salaryStr.isEmpty()) {
double salary = Double.parseDouble(salaryStr);
employee.setSalary(salary);
}
System.out.println("Employee information updated successfully.");
} else {
System.out.println("Employee not found.");
}
}
private static void changeEmployeeDepartment() {
System.out.print("Enter employee ID: ");
int id = scanner.nextInt();
System.out.print("Enter new department ID: ");
int newDepartmentId = scanner.nextInt();
scanner.nextLine(); // consume newline
Employee employee = employees.get(id);
Department newDepartment = departments.get(newDepartmentId);
if (employee != null && newDepartment != null) {
Department oldDepartment = departments.get(employee.getDepartmentId());
if (oldDepartment != null) {
oldDepartment.removeEmployee(employee);
}
newDepartment.addEmployee(employee);
employee.setDepartment(newDepartment.getName());
System.out.println("Employee department changed successfully.");
} else {
System.out.println("Employee or department not found.");
}
}
private static void promoteOrDemoteEmployee() {
System.out.print("Enter employee ID: ");
int id = scanner.nextInt();
System.out.print("Enter new position: ");
String newPosition = scanner.next();
scanner.nextLine(); // consume newline
Employee employee = employees.get(id);
if (employee != null) {
employee.setPosition(newPosition);
System.out.println("Employee promoted/demoted successfully.");
} else {
System.out.println("Employee not found.");
}
}
private static void hierarchyManagementMenu() {
System.out.println("\nHierarchy Management Menu:");
System.out.println("1. Find supervisor");
System.out.println("2. Find subordinates");
System.out.println("3. Analyze organizational structure");
System.out.println("4. Back to main menu");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine(); // consume newline
switch (choice) {
case 1:
findSupervisor();
break;
case 2:
findSubordinates();
break;
case 3:
analyzeStructure();
break;
case 4:
return; // Back to main menu
default:
System.out.println("Invalid choice. Please try again.");
}
}
private static void findSupervisor() {
System.out.print("Enter employee ID: ");
int id = scanner.nextInt();
scanner.nextLine(); // consume newline
Employee employee = employees.get(id);
if (employee != null && employee.getSupervisor() != null) {
System.out.println("Supervisor: " + employee.getSupervisor().getName());
} else {
System.out.println("Supervisor not found.");
}
}
private static void findSubordinates() {
System.out.print("Enter supervisor ID: ");
int id = scanner.nextInt();
scanner.nextLine(); // consume newline
Employee supervisor = employees.get(id);
if (supervisor != null) {
List<Employee> subordinates = supervisor.getSubordinates();
if (!subordinates.isEmpty()) {
System.out.println("Subordinates:");
for (Employee subordinate : subordinates) {
System.out.println(subordinate.getName());
}
} else {
System.out.println("No subordinates found.");
}
} else {
System.out.println("Supervisor not found.");
}
}
private static void analyzeStructure() {
System.out.println("Analyzing organizational structure...");
// Implement the logic for analyzing the organizational structure
// For example, calculate and print the hierarchy depth
}
private static void departmentManagementMenu() {
System.out.println("\nDepartment Management Menu:");
System.out.println("1. Create department");
System.out.println("2. Assign employee to department");
System.out.println("3. Manage department budget");
System.out.println("4. Back to main menu");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine(); // consume newline
switch (choice) {
case 1:
createDepartment();
break;
case 2:
assignEmployeeToDepartment();
break;
case 3:
manageDepartmentBudget();
break;
case 4:
return; // Back to main menu
default:
System.out.println("Invalid choice. Please try again.");
}
}
private static void createDepartment() {
System.out.print("Enter department name: ");
String name = scanner.nextLine();
System.out.print("Enter department budget: ");
double budget = scanner.nextDouble();
scanner.nextLine(); // consume newline
Department newDepartment = new Department(name, departmentIdCounter++, budget);
departments.put(newDepartment.getId(), newDepartment);
System.out.println("Department created successfully.");
}
private static void assignEmployeeToDepartment() {
System.out.print("Enter employee ID: ");
int id = scanner.nextInt();
System.out.print("Enter department ID: ");
int departmentId = scanner.nextInt();
scanner.nextLine(); // consume newline
Employee employee = employees.get(id);
Department department = departments.get(departmentId);
if (employee != null && department != null) {
department.addEmployee(employee);
employee.setDepartment(department.getName());
System.out.println("Employee assigned to department successfully.");
} else {
System.out.println("Employee or department not found.");
}
}
private static void manageDepartmentBudget() {
System.out.print("Enter department ID: ");
int id = scanner.nextInt();
System.out.print("Enter new budget: ");
double budget = scanner.nextDouble();
scanner.nextLine(); // consume newline
Department department = departments.get(id);
if (department != null) {
department.setBudget(budget);
System.out.println("Department budget updated successfully.");
} else {
System.out.println("Department not found.");
}
}
private static void performanceTrackingMenu() {
System.out.println("\nPerformance Tracking Menu:");
System.out.println("1. Track employee performance");
System.out.println("2. Generate performance reports");
System.out.println("3. Back to main menu");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine(); // consume newline
switch (choice) {
case 1:
trackPerformance();
break;
case 2:
generatePerformanceReports();
break;
case 3:
return; // Back to main menu
default:
System.out.println("Invalid choice. Please try again.");
}
}
private static void trackPerformance() {
System.out.print("Enter employee ID: ");
int id = scanner.nextInt();
scanner.nextLine(); // consume newline
Employee employee = employees.get(id);
if (employee != null) {
System.out.print("Enter performance metric name: ");
String metricName = scanner.nextLine();
System.out.print("Enter performance metric value: ");
int metricValue = scanner.nextInt();
scanner.nextLine(); // consume newline
employee.addPerformanceMetric(metricName, metricValue);
System.out.println("Performance tracked successfully.");
} else {
System.out.println("Employee not found.");
}
}
private static void generatePerformanceReports() {
System.out.println("Generating performance reports...");
for (Employee employee : employees.values()) {
System.out.println("Employee: " + employee.getName());
System.out.println("Performance Metrics: " + employee.getPerformanceMetrics());
}
}
private static void securityMenu() {
System.out.println("\nSecurity and Access Control Menu:");
System.out.println("1. Authenticate user");
System.out.println("2. Change login credentials");
System.out.println("3. Back to main menu");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine(); // consume newline
switch (choice) {
case 1:
authenticateUser();
break;
case 2:
changeLoginCredentials();
break;
case 3:
return; // Back to main menu
default:
System.out.println("Invalid choice. Please try again.");
}
}
private static void authenticateUser() {
// Implement authentication logic here
System.out.print("Enter username: ");
String username = scanner.nextLine();
System.out.print("Enter password: ");
String password = scanner.nextLine();
// Simulate authentication process
if ("admin".equals(username) && "admin123".equals(password)) {
System.out.println("Authentication successful.");
} else {
System.out.println("Authentication failed.");
}
}
private static void changeLoginCredentials() {
// Implement change login credentials logic here
System.out.print("Enter old password: ");
String oldPassword = scanner.nextLine();
System.out.print("Enter new password: ");
String newPassword = scanner.nextLine();
// Simulate change password process
if ("admin123".equals(oldPassword)) {
// Change password logic here
System.out.println("Password changed successfully.");
} else {
System.out.println("Old password is incorrect.");
}
}
}
class Employee {
private String name;
private int id;
private String position;
private String department;
private double salary;
private Employee supervisor;
private List<Employee> subordinates;
private Map<String, Integer> performanceMetrics;
public Employee(String name, int id, String position, String department, double salary) {
this.name = name;
this.id = id;
this.position = position;
this.department = department;
this.salary = salary;
this.subordinates = new ArrayList<>();
this.performanceMetrics = new HashMap<>();
}
public int getId() {
return id;
}
public void setPosition(String position) {
this.position = position;
}
public void setSalary(double salary) {
this.salary = salary;
}
public void setDepartment(String department) {
this.department = department;
}
public void setSupervisor(Employee supervisor) {
this.supervisor = supervisor;
}
public Employee getSupervisor() {
return supervisor;
}
public List<Employee> getSubordinates() {
return subordinates;
}
public void addSubordinate(Employee subordinate) {
subordinates.add(subordinate);
}
public void removeSubordinate(Employee subordinate) {
subordinates.remove(subordinate);
}
public void addPerformanceMetric(String metricName, int metricValue) {
performanceMetrics.put(metricName, metricValue);
}
public Map<String, Integer> getPerformanceMetrics() {
return performanceMetrics;
}
public String getName() {
return name;
}
public String getDepartmentId() {
return department;
}
}
class Department {
private String name;
private int id;
private double budget;
private List<Employee> employees;
public Department(String name, int id, double budget) {
this.name = name;
this.id = id;
this.budget = budget;
this.employees = new ArrayList<>();
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public void setBudget(double budget) {
this.budget = budget;
}
public void addEmployee(Employee employee) {
employees.add(employee);
}
public void removeEmployee(Employee employee) {
employees.remove(employee);
}
}
class PerformanceTracking {
private Map<Integer, Map<String, Integer>> performanceData = new HashMap<>();
public void trackPerformance(int employeeId, String metricName, int metricValue) {
performanceData.putIfAbsent(employeeId, new HashMap<>());
performanceData.get(employeeId).put(metricName, metricValue);
}
public Map<String, Integer> getPerformanceMetrics(int employeeId) {
return performanceData.getOrDefault(employeeId, new HashMap<>());
}
public void generateReports() {
for (Map.Entry<Integer, Map<String, Integer>> entry : performanceData.entrySet()) {
int employeeId = entry.getKey();
Map<String, Integer> metrics = entry.getValue();
System.out.println("Employee ID: " + employeeId);
System.out.println("Performance Metrics: " + metrics);
}
}
}