//学生类
public class Student implements Comparable{
public String name; //姓名
public int age; //年龄
public int score; //考试成绩
//构造函数,供类进行一些初始化信息
public Student(String name,int age,int score){
this.name=name;
this.age=age;
this.score=score;
}
@Override
//实现Comparable比较器的方法,按照自己的需求进行排序
public int compareTo(Object obj) {
// TODO Auto-generated method stub
if(!(obj instanceof Student) ){
throw new RuntimeException("不是学生类!");
}
Student s=(Student)obj;
int num=new Integer(score).compareTo(s.score);
if(num==0){
num=name.compareTo(s.name);
}
return num;
}
}