mardi 1 septembre 2020

Getting an "Operator '&&' cannot be applied to 'boolean', 'int'" error and I'm unsure why

I'm writing a method that is to determine if two "Course" objects, where a "Course" object is comprised of courseName (String), department (String), code (int), section (byte), and instructor (String), and returns "true" if the objects have equivalent values. However, in the portion of the method that checks if they original "Course" object and the new "Course" object are equal, I am getting the above error.

Code for reference:

public boolean equals(Course obj){
    if(obj instanceof Course){

        Course c = (Course)obj;

        if(this.courseName.equals(course.getName()) &&
                this.department.equals(course.getDepartment()) &&
                (this.code==course.getCode()) &&
                (Byte.compare(this.section, course.getSection())) &&
                this.instructor.equals(course.getInstructor()))
            return true;
    }
    return false;
}

Error is listed as being on the line if(this.courseName.equals(course.getName()) &&, but I'm unsure if it's referring to the entire if statement.

Thank you!

Aucun commentaire:

Enregistrer un commentaire