As you can see my student class is a subclass of person. I have used the standard .equals() method in the person super class. In my .equals() for the child class Student I am getting an error on third line of the method where I cast a new Student object from "other". The error reads "Cannot find Symbol" and occurs on this line Student newStudent = Student(other); ^ Why is the symbol not recognized?
public class Student extends Person {
private double avgGPA;
private int gtID;
private String[] classes;
public Student(String name, int age, String hometown, int gtID, double avgGPA, String[] classes){
super(name,age,hometown);
this.avgGPA = avgGPA;
this.gtID = gtID;
this.classes = classes;
}
public double getAvgGPA(){
return avgGPA;
}
public String[] getClasses(){
return classes;
}
public int getGTID(){
return gtID;
}
public String toString(){
return super.toString() + " with gtid " + gtID;
}
public boolean equals(Object other){
if (super.equals(other)){
Student newStudent = Student(other);
if (this.avgGPA != newStudent.avgGPA){
return false;
} else if ( this.gtID != newStudent.gtID){
return false;
} else if ( this.classes.length != newStudent.classes.length){
return false;
} else {
for (int i = 0; i < this.classes.length; i++) {
if (this.classes[i] != newStudent.classes[i]){
return false;
}else {
return true;
}
}
}
}
}
}