I'm trying to practice a little, but the book dosen't give me the solution. There's still one function missing in this piece of code and I'm wondering hwo I complete it.
I suppose it's something like this...Code:public class Person { private String firstName; private String lastName; private String ID; // user ID private String password; private int userType; // 1 student 2 faculty public Person() { } public Person(String ID, String firstName, String lastName, String password, int userType) { this.ID = ID; this.firstName = firstName; this.lastName = lastName; this.password = password; this.userType = userType;//1 faculty 2 student } public String toString() { return ID+ " " + Application.addSpaces((firstName + " " + lastName),18); } public boolean equals(Object theOtherObject) { // YOU CAN CHANGE EVERYTHING IN THIS FUNCTION INCLUDING THE STAMENTS: // boolean result = false; // return result; boolean result = false; // INCOMPLETE FUNCTION // ooooooooooooooooooo // oooooooo ooooooooo // oooooooo ooooooooo // oooooooo ooooooooo // oooooooo ooooooooo // ooooooooooooooooooo // oooooooo ooooooooo // ooooooooooooooooooo return result; } public boolean validation(String ID, String password) { return ( this.ID.equals(ID)&& this.password.equals(password) ); } public int getUserType() { return userType; } public String getUserID() { return ID; } }
Do I just have to compare those attributes?Code:public boolean equals(Object theOtherObject) {boolean result = false; if((theOtherObject!=null) && (theOtherObject instanceof Person)) { Person otherPerson = (Person) theOtherObject; if((this.firstName.equals(otherPerson) *****&& (this.userType== otherPerson.userType)) { result = true; } return result; } }
this.ID = ID;
this.firstName = firstName;
this.lastName = lastName;
this.password = password;
this.userType = userType
So I would have to modify this line here:
if((this.firstName.equals(otherPerson) *****&& (this.userType== otherPerson.userType))
Do I just have to add them now? thank you!




Reply With Quote