以下程序报错,请各位大牛帮忙!!!
packageorg.lxh.Erchashu;importjava.util.Comparator;;publicclassStudentComparatorimple...
package org.lxh.Erchashu;
import java.util.Comparator;;
public class StudentComparator implements Comparable<Student> {
//错误1:The type StudentComparator must implement the inherited abstract method Comparable<Student>.compareTo(Student)
public int compare(Student stu1, Student stu2){
if(stu1.getScore()>stu2.getScore()){
return -1 ;
}else if(stu1.getScore()<stu2.getScore()){
return 1 ;
}else{
if(stu1.getAge()>stu2.getAge()){
return 1;
}else if(stu1.getAge()<stu2.getAge()){
return -1 ;
}else{
return 0 ;
}
}
}
public boolean equals(Object obj) {
return this.equals(obj) ;
}
}
//错误2:The method getScore() is undefined for the type Student
The method getAge() is undefined for the type Student 展开
import java.util.Comparator;;
public class StudentComparator implements Comparable<Student> {
//错误1:The type StudentComparator must implement the inherited abstract method Comparable<Student>.compareTo(Student)
public int compare(Student stu1, Student stu2){
if(stu1.getScore()>stu2.getScore()){
return -1 ;
}else if(stu1.getScore()<stu2.getScore()){
return 1 ;
}else{
if(stu1.getAge()>stu2.getAge()){
return 1;
}else if(stu1.getAge()<stu2.getAge()){
return -1 ;
}else{
return 0 ;
}
}
}
public boolean equals(Object obj) {
return this.equals(obj) ;
}
}
//错误2:The method getScore() is undefined for the type Student
The method getAge() is undefined for the type Student 展开
1个回答
2013-08-31
展开全部
Student类中,没有定义 getScore()方法、没有getAge()方法
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询