java日期排序因该怎么写?(实例)谢谢!
importjava.util.*;publicclassEmployeeSortTest{publicstaticvoidmain(String[]args){Empl...
import java.util.*;
public class EmployeeSortTest
{ public static void main(String[] args)
{ Employee5[] staff=new Employee5[3];
staff[0]=new Employee5("liyi",5000,1988,8,23);
staff[1]=new Employee5("wangli",4000,1988,5,17);
staff[2]=new Employee5("liwei",6000,1986,6,23);
Arrays.sort(staff);
for(Employee5 e:staff)
{ System.out.println("name="+e.getName()+",salary="+e.getSalary()+",hireDay="+e.getHireDay());
}
}
}
class Employee5 implements Comparable<Employee5>
{ public Employee5(String n,double s,int year,int month,int day)
{ name=n;
salary=s;
GregorianCalendar calendar=new GregorianCalendar(year,month,day);
hireDay=calendar.getTime();
}
public String getName()
{ return name;
}
public double getSalary()
{ return salary;
}
public Date getHireDay()
{ return hireDay;
}
public int compareTo(Employee5 other)
{ 这里应该怎么写?
}
private String name;
private Date hireDay;
private double salary;
} 展开
public class EmployeeSortTest
{ public static void main(String[] args)
{ Employee5[] staff=new Employee5[3];
staff[0]=new Employee5("liyi",5000,1988,8,23);
staff[1]=new Employee5("wangli",4000,1988,5,17);
staff[2]=new Employee5("liwei",6000,1986,6,23);
Arrays.sort(staff);
for(Employee5 e:staff)
{ System.out.println("name="+e.getName()+",salary="+e.getSalary()+",hireDay="+e.getHireDay());
}
}
}
class Employee5 implements Comparable<Employee5>
{ public Employee5(String n,double s,int year,int month,int day)
{ name=n;
salary=s;
GregorianCalendar calendar=new GregorianCalendar(year,month,day);
hireDay=calendar.getTime();
}
public String getName()
{ return name;
}
public double getSalary()
{ return salary;
}
public Date getHireDay()
{ return hireDay;
}
public int compareTo(Employee5 other)
{ 这里应该怎么写?
}
private String name;
private Date hireDay;
private double salary;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询