public int compareTo(Student o) {
/*
* 先按照语文成绩排序,分数高的在前面
* 语文成绩一样的,按照数学成绩排序,分数大的在前面
* 数学成绩一样的,按照英语成绩排序,分数大的在前面
*
* 分数都相同,按照姓名的自然顺序进行排序
*/
int yuwen = this.chinese-o.chinese;
if (yuwen==0) {
int shuxue = this.math-o.math;
if (shuxue==0) {
int yingyu = this.english-o.english;
if (yingyu==0) {
return this.name.compareTo(o.name);
}else{
return -yingyu;
}
}else{
return -shuxue;
}
}else{
return -yuwen;
}
}
} |
|