heres my code for a library application
package com.accenture.totalbeginner;
public class Person {
private String name;
private int maximumbooks;
pub
getMaximumbooks() returns a primitive type int not an Object. You have to compare it with == or in you case != (not equals)
if (this.getMaximumbooks() != p1.getMaximumbooks())
{
return false;
}
return true;
Just use == if you're comparing primitives.
Also, try not to use getters when working into the class because you have already access to all the fields (private or not).
public boolean equals(Person p1)
{
return this.maximumBooks == p1.getMaximumBooks();
}
equals() is used for Objects (String, Integer, etc...)
For primitives like int, boolean, char etc, you have to use ==