黑马程序员技术交流社区
标题:
对一个班级的同学按照特定规律进行排序1
[打印本页]
作者:
Sou男人
时间:
2015-5-18 23:08
标题:
对一个班级的同学按照特定规律进行排序1
package Test;
public class Student implements Comparable<Student>{
private int score;
private int age;
private String name;
public Student() {
super();
}
public Student( String name, int age,int score) {
super();
this.score = score;
this.age = age;
this.name = name;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Student [score=" + score + ", age=" + age + ", name=" + name+ "]";
}
public int compareTo(Student s){
int num = s.score - this.score;
int num1 = num==0?(this.age - s.age):num;
int num2 = num1==0?s.name.compareTo(this.name):num1;
return num2;
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2