-
Notifications
You must be signed in to change notification settings - Fork 0
/
Director.java
145 lines (99 loc) · 3.1 KB
/
Director.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
133
134
135
136
137
138
139
140
141
142
143
144
145
package lab4;
import java.util.ArrayList;
/**
* @author Fei Alm
* @version 1.0
* @since 2019
*/
public class Director extends Employee{
private ArrayList<Worker> workersThisDirectorList;
//This constructor is called with the details of the worker
//and it passes these on to the constructor of the superclass
/**
* Constructor for class Director.
* Makes a new list for every new director
*
* @param firstName - name of worker/director, type String
* @param secondName - surname of worker/director, type String
* @param eNumber - employee number, type int
* @param salary - salary for employee, type double
*/
public Director (String firstName, String secondName, int eNumber, double salary) {
super(firstName, secondName, eNumber, salary);
workersThisDirectorList = new ArrayList<Worker>();
}
/***
* Add worker into the the director list for his/hers employees
* @param aWorker - a worker that works for a director, type Worker
*/
// lägger in worker som arbetar för en viss director i array
public void addEmployee(Worker aWorker) {
workersThisDirectorList.add(aWorker);
}
/**
* @param aDirector - the director that will be compared with the other directors, type Employee
*/
public int compareTo(Employee aDirector) {
// hämta en directors salary
// Varför samma method som gör samma sak i director o worker??? varför inte i Employee
// sortera BYNAME, BYSALARY, BYTAXES
double aDirectorsSalary = aDirector.getSalary();
double aDirectorsTax = aDirector.computeTaxes();
int a = 0;
int comparingNames = this.secondName.compareTo(aDirector.secondName);
if (Employee.sortCriterion == Employee.BYNAME) {
a = comparingNames;
}
if(Employee.sortCriterion == Employee.BYSALARY) {
if(this.getSalary() == aDirectorsSalary) {
a =0;
}
if(this.getSalary() < aDirectorsSalary) {
a = 1;
}
if(this.getSalary() > aDirectorsSalary) {
a = -1;
}
}
if(Employee.sortCriterion == Employee.BYTAXES) {
if(this.computeTaxes() == aDirectorsTax) {
a =0;
}
if(this.computeTaxes() < aDirectorsTax) {
a = 1;
}
if(this.computeTaxes() > aDirectorsTax) {
a = -1;
}
}
return a;
}
/**
* Method takes no argument
* Calculate the bonus a director will get according to how many workers he/she has
*
* @return sum_bonus , the sum of the bonus a director will get
*/
public double computeBonus() {
double sum_bonus = 0.0;
double bonus = 0.1;
for (int i = 0; i < workersThisDirectorList.size(); i++) {
sum_bonus += workersThisDirectorList.get(i).salary;
}
sum_bonus= sum_bonus*bonus;
return sum_bonus;
}
/**
* Takes no argument
* Calculates the tax for a director
*
* @return result
* */
public double computeTaxes() {
double taxes = 0.25;
double result = 0.0;
double the_bonus = this.computeBonus();
result = (the_bonus + salary)*taxes;
return result;
}
}