Repository navigation
Expand file tree
/
Copy pathManager.java
More file actions
101 lines (85 loc) · 2.95 KB
/
Copy pathManager.java
File metadata and controls
101 lines (85 loc) · 2.95 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
import java.util.ArrayList;
import java.util.Scanner;
public class Manager implements EmployeeServices {
// following variable stores all the employees
private static ArrayList<Employee> employees = new ArrayList<>();
private static Scanner sc = new Scanner(System.in);
public void addEmployee(Employee e) {
employees.add(e);
}
/**
* following method prints list of all employees
*/
public void printEmployee() {
System.out.println("\nList of Employees => ");
for (Employee e : employees) {
System.out.println(e);
}
}
/**
* following method returns yearly salary of all employee
*/
public double calculateSalary(String id) {
for (Employee e : employees) {
if (id.equals(e.getId())) {
return e.getSalary();
}
}
return 0;
}
/**
* following method search for the specified id in employee list it returns
* Employee object, if employee found, otherwise null
*
* @param id
* @return
*/
public Employee findEmployeeById(String id) {
for (Employee e : employees) {
if (id.equals(e.getId())) {
System.out.println("Employee with ID: " + id + " found =>");
System.out.println(e);
return e;
}
}
System.out.println("Employee with ID: " + id + " NOT found =>");
return null; // otherwise
}
public void updateEmployee(String id) {
Employee e = findEmployeeById(id);
if (e != null) {
System.out.print("Enter updated name [press enter for no change] : ");
String name = sc.nextLine();
if (name.length() > 0) {
e.setName(name);
}
System.out.print("Enter updated salary [enter 0 for no change] : ");
double salary = sc.nextDouble();
sc.nextLine();
if (salary > 0) {
e.setSalary(salary);
}
System.out.print("Enter updated city [press enter for no change] : ");
String city = sc.nextLine();
if (city.length() > 0) {
e.address.setCity(city);
}
System.out.print("Enter updated state [press enter for no change] : ");
String state = sc.nextLine();
if (state.length() > 0) {
e.address.setCity(state);
}
System.out.println("Emplyee updated successfully...");
}
}
public void deleteEmployee(String id) {
for (Employee e : employees) {
if (id.equals(e.getId())) {
employees.remove(e);
System.out.println("Emplyee deleted successfully...");
return;
}
}
System.out.println("Emplyee not found...");
}
}