-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployeeTest.java
More file actions
60 lines (50 loc) · 1.62 KB
/
EmployeeTest.java
File metadata and controls
60 lines (50 loc) · 1.62 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
package EmployeeTest;
import java.time.LocalDate;
/**
* This program tests the chapter04.EmployeeTest.EmployeeTest class.
*
* @author Cay Horstmann
* @version 1.12 2015-05-08
*/
public class EmployeeTest {
public static void main(String[] args) {
// fill the staff array with three chapter04.EmployeeTest.EmployeeTest objects
Employee[] staff = new Employee[3];
staff[0] = new Employee("Carl Cracker", 75000, 1987, 12, 15);
staff[1] = new Employee("Harry Hacker", 50000, 1989, 10, 1);
staff[2] = new Employee("Tony Tester", 40000, 1990, 3, 15);
// raise everyone's salary by 5%
for (Employee employee : staff)
employee.raiseSalary(5);
// print out information about all EmployeeTest objects
for (Employee employee : staff) {
System.out.println("name = " + employee.getName() +
", salary = " + employee.getSalary() +
", hireDay = " + employee.getHireDay()
);
}
}
}
class Employee {
private final String name;
private final LocalDate hireDay;
private double salary;
public Employee(String name, double salary, int year, int month, int day) {
this.name = name;
this.salary = salary;
hireDay = LocalDate.of(year, month, day);
}
public String getName() {
return name;
}
public double getSalary() {
return salary;
}
public LocalDate getHireDay() {
return hireDay;
}
public void raiseSalary(double byPercent) {
double raise = salary * byPercent / 100;
salary += raise;
}
}