-
Notifications
You must be signed in to change notification settings - Fork 0
/
Employee.java
126 lines (93 loc) · 2.99 KB
/
Employee.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
package lab4;
/**
* @author Fei Alm
* @version 1.0
* @since 2019
*/
public abstract class Employee extends Object implements Comparable <Employee>{
public static final int BYNAME = 0;
public static final int BYSALARY = 1;
public static final int BYTAXES = 2;
// de ska användas för att ändra sortCriterion till 0, 1, 2
static int sortCriterion = 0;
// sätter den som noll
// ska ändra hur man sorterar
double salary;
int employeeNumber;
String secondName;
String firstName;
/**
* This method receives name, surname, employee number and salary in the arguments.
* The arguments initialize the variables (double) salary, (int) employeeNumber, (String) secondName, (String) firstName;
*
* @param name1 - type string
* @param name2 - type string
* @param employeeID - type int
* @param aSalary - type double
*/
public Employee(String name1, String name2, int employeeID, double aSalary) {
firstName = name1;
secondName = name2;
employeeNumber = employeeID;
salary = aSalary;
}
/**
* Change what type of sorting option that is used,
* BYNAME, BYSALARY, BYTAXES
*
* @param sortingOption - type int, it is the sorting option that the criterion will be changed into
*/
public static void changeCriterion(int sortingOption) {
if (sortingOption != BYNAME && sortingOption != BYSALARY && sortingOption != BYTAXES) {
System.out.println("Option doesn't exist!");
}
else
{
sortCriterion = sortingOption;
}
}
// This instance method returns the taxes paid by the employee
// it is implemented in the subclasses, alltså ska INGEN kod skrivas för den här
// kod för denna method skrivs i Director och Worker
public abstract double computeTaxes();
/**
* Returns the name of a employee
* @return firstName + secondName
*/
public String getName() {
return firstName + secondName;
}
/**
* Returns ID-number of a employee
* @return employeeNumber
*/
public int getNumber() {
return employeeNumber;
}
/**
* Returns the salary of a employee
* @return salary
*/
public double getSalary() {
return salary;
}
/**
* Writes out information about every employee
*/
public String toString() {
// return information about employee
// firstname, second, employee number ska alltid vara med i return
// sedan kan man lägga till mera beroende på vilken sorteringstyp man vill ha
String result= String.format( "%-15s%-15s%-10d", firstName, secondName, employeeNumber);
if (sortCriterion == BYSALARY) {
// här lägger till salary till string
result = result + String.format("%-8f" ,salary) ;
}
if(sortCriterion == BYTAXES){
// här lägger till salary OCH taxes till string
// double tax = computeTaxes(); //hämtar tax från director eller worker, fungerar för båda
result = result + String.format("%-8f" , computeTaxes());
}
return result;
}
}