This:
Code:
public PhoneEntry(PhoneEntry other)
{
//in here should be "copy the contents of the parameter
//to the current object" but I don't know what that means........
}
Is a copy constructor. It allows you to clone an existing object without making the class cloneable. Simply set the values of "this" to the values provided in "other". I won't read the assignment itself, but unless it says otherwise, I would presume a shallow copy is sufficient.
Equals is incorrect. Its definition should be:
Code:
public boolean equals(Object other);
Unless specified otherwise. This will override the function equals (which means you really *should* override the hashcode as well), so any functionality that uses equals for comparisons will be able to function properly. Such things like collections will do this.
This is slightly trickier. Notice the definition is only of type Object to override (although I haven't checked in Java 7 if its generic or not), so this is what you have to do:
- Set boolean bResult to false
- If other instanceof PhoneEntry then
- Execute .equals on name, and phone number to compare the results. A simple ternary operation consisting of an && between the two comparisons for assignment. Assign result to bResult
- Return bResult
No need to overload the equals.
Edit:
Also worth a mention; boolean != Boolean. One is a primitive and another is a class wrapper.