import java.util.Arrays; public class Grapeh { public static void main(String[] args) { Employee[] staff=new Employee[3]; staff[0]=new Employee("heln",5003); staff[1]=new Employee("mell",1000); staff[2]=new Employee("kell",500); Arrays.sort(staff); for(Employee e:staff) System.out.println("name="+e.getName()+",salary="+e.getSalary()); } }
public class Employee implements Comparable<Employee>{ private String name; private double salary; 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 Double.compare(salary, other.salary); } }
时间: 2024-10-05 22:40:26