Given the header:
public boolean equals(Name otherName)
I’m supposed to compare two name objects for equality. What I have right now is:
public boolean equals(Name otherName){
return (name1.equalsIgnoreCase(name2));
}
However, I get an identifier expected error. I think it would work if I change the parameters but the assignment asks that I use that header. What am I doing wrong?
Here is the name constructor:
public Name (String first, String middle, String last){
firstName = first;
middleName = middle;
lastName = last;
}
You get ” get an identifier expected error.” because
name1andname2are defined. Inside equals method you pass another object so refer it asotherNameand the object itself is accessible asthis.Try
or
Of course, you should have
equalsIgnoreCaseimplemented forNameclass.