Skip to content

Commit 067496c

Browse files
committed
用户自定义类
1 parent 0ebb355 commit 067496c

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

Part3/EmployeeTest.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import java.util.*;
2+
3+
public class EmployeeTest {
4+
public static void main(String[] args) {
5+
Employee[] staff = new Employee[3];
6+
staff[0] = new Employee("Calrl Cracker", 75000, 1987, 12, 15);
7+
staff[1] = new Employee("Harry Hacker", 50000, 1989, 10, 1);
8+
staff[2] = new Employee("Tony Tester", 40000, 1990, 3, 15);
9+
10+
for (Employee e : staff) {
11+
e.raiseSalary(5);
12+
}
13+
14+
for (Employee e : staff) {
15+
System.out.println(
16+
"name = " + e.getName() +
17+
", salary = " + e.getSalary() +
18+
", hireDay = " + e.getHireDay()
19+
);
20+
}
21+
}
22+
}
23+
24+
class Employee {
25+
private String name;
26+
private double salary;
27+
private Date hireDay;
28+
29+
public Employee(String n, double s, int year, int month, int day) {
30+
name = n;
31+
salary = s;
32+
GregorianCalendar calendar = new GregorianCalendar(year, month - 1, day);
33+
hireDay = calendar.getTime();
34+
}
35+
36+
public String getName() {
37+
return name;
38+
}
39+
40+
public double getSalary() {
41+
return salary;
42+
}
43+
44+
public Date getHireDay() {
45+
return hireDay;
46+
}
47+
48+
public void raiseSalary(double byPercent) {
49+
double raise = salary * byPercent / 100;
50+
salary += raise;
51+
}
52+
}
53+

0 commit comments

Comments
 (0)