-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompanyModel.java
132 lines (111 loc) · 3.34 KB
/
CompanyModel.java
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
package companyManager;
import java.util.List;
import java.util.TreeMap;
import static java.lang.System.out;
public class CompanyModel
{
private TreeMap<Integer, Employee> employeeTreeMap = new TreeMap <>();
public CompanyModel() {}
public void addEmployee(Employee employee)
{
employeeTreeMap.put(employee.getId(),employee);
}
public void addEmployee(List<Employee> employeeList)
{
for(Employee employee : employeeList)
{
employeeTreeMap.put(employee.getId(), employee);
}
}
public void removeEmployee(Employee employee) throws Exception
{
removeEmployee(employee.getId());
}
public void removeEmployee(int id) throws Exception
{
if(employeeTreeMap.containsKey(id))
{
employeeTreeMap.remove(id);
}
else throw new Exception("Invalid ID");
}
public Employee getEmployee(int id) throws Exception
{
if(employeeTreeMap.get(id) != null)
{
return employeeTreeMap.get(id);
}
else throw new Exception("Invalid ID");
}
public boolean contains(int id)
{
return employeeTreeMap.containsKey(id);
}
public void updateEmployee(Employee employee)
{
employeeTreeMap.replace(employee.getId(), employee);
}
public int size()
{
return employeeTreeMap.size();
}
public void raiseAll() throws Exception
{
if(size() == 0) throw new Exception("No employee yet!");
else
{
HourlyEmployee.RAISE_ALL();
SalariedEmployee.RAISE_ALL();
Manager.RAISE_ALL();
}
}
public void raiseThis(int id) throws Exception
{
if(size() == 0) throw new Exception("No employee yet!");
if(id >= 100 && id <= 999)
{
Manager.RAISE_THIS(id);
}
else if(id >= 1000 && id <= 4999)
{
SalariedEmployee.RAISE_THIS(id);
}
else if(id >= 5000 && id <= 9999)
{
HourlyEmployee.RAISE_THIS(id);
}
else throw new Exception("Invalid Employee ID");
}
@Override
public String toString()
{
int i = 1;
int j = 1;
int k = 1;
StringBuilder result = new StringBuilder("\n|---------------------------------------\n");
result.append("|").append("\t").append("Manager(s): ").append("\n");
result.append("|").append("\t").append("Salaried Employee(s): ").append("\n");
result.append("|").append("\t").append("Hourly Employee(s): ").append("\n");
for(Employee employee : employeeTreeMap.values())
{
if(employee.getId() <= 999)
{
result.append("|").append("\t\t").append(i).append(": ").append(employee).append("\n");
i++;
}
else if(employee.getId() <= 4999)
{
result.append("|").append("\t\t").append(j).append(": ").append(employee).append("\n");
j++;
}
else
{
result.append("|").append("\t\t").append(k).append(": ").append(employee).append("\n");
k++;
}
}
result.append(result);
result.append("|---------------------------------------\n");
return result + "\n";
}
}