-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployeeSortTest.java
More file actions
60 lines (52 loc) · 1.05 KB
/
EmployeeSortTest.java
File metadata and controls
60 lines (52 loc) · 1.05 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
import java.util.*;
/**
*EmployTest.java
*Time:2013-10-6
*@author zhiliang
*
* */
public class EmployeeSortTest
{
/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
Employee [] staff = new Employee[4];
staff[0] = new Employee("Harry Hacker", 35000);
staff[1] = new Employee("Cal1 Cracker", 75000);
staff[2] = new Employee("Tony Tester", 38000);
staff[3] = new Employee("ZhiLiang Manger", 8970000);
Arrays.sort(staff);
for (Employee e : staff)
System.out.println("Name=" + e.getName() + ",Salary=" + e.getSalary());
}
}
class Employee implements Comparable<Employee>
{
public Employee(String n, double s)
{
name = n;
salary = s;
}
public String getName()
{
return name;
}
public double getSalary()
{
return salary;
}
public void raiseSalary(double byPercent)
{
double raise = salary * byPercent / 100;
salary += raise;
}
public int compareTo(Employee other)
{
return (int) (this.salary - other.salary);
}
private String name;
private double salary;
}