The Grades & Courses are not equal...
Course Title: Physics
Grade: A-
Course Title: Physics
Grade: A-
以上是我的输出。情况应该不是这样......我在其他类中使用Equals方法(比较字符串的内容),如下所示:
//Equals Method
public static boolean equals(CourseGrade a, CourseGrade b) {
return a.getCourse().equalsIgnoreCase(b.getGrade());
一切似乎都是狡猾的 - 我没有抛出任何错误。但是,正如您从输出中看到的那样,答案是错误的。它应该是假的,并且它应该输出一行,“等级和课程不相等......”为清楚起见:
public static void main(String[] args) {
CourseGrade a = new CourseGrade("Physics", "A-");
CourseGrade b = new CourseGrade("Physics", "A-");
if (a.equals(b)){
System.out.println("The Grades & Courses are equal...");
}
else {
System.out.println("The Grades & Courses are not equal...");
}
System.out.println();
System.out.println(a.toString());
System.out.println(b.toString());
我错过了什么?