Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a name class that encapsulates a person\'s name. It has three private inst

ID: 3642223 • Letter: W

Question

Write a name class that encapsulates a person's name. It has three private instance variables: firstName, middleName, and lastName. The class has a read method, getFirstName(), getMiddleName(), getLastName(), setFirstName(String), setMiddleName(String), setLastName(sString), changeNameTo(String, String, string), changeNameTo(Name), Name add(name), getFullNameToUpperCase(), toString() and equals(). The add method returns a Name instance. The returned instance first name is the parameter's first name, the returned instance middle name is the parameter's middle name, and the returned instance last name is this.lastName hyphenated with the parameter's last Name.

This is the main program to be used as a demo:

public class NameDemo {
}
public static void main(String[] args) {
}
Name brother = new Name( );
Name schoolFriend = new Name( );
Name neighbor = new Name();
System.out.println("Enter your brother's name.");
brother.readName( );
System.out.println("Enter your school friend's name.")
schoolFriend.readName( );
System.out.println("Enter your neighbor's name.");
neighbor.readName( );
System.out.println(" Your neighbor's middle name is " + neighbor.getMiddleName());
Your brother's name is " + brother);
if(neighbor.equals(brother)) {
System.out.println(" Your neighbor's name is the same

Explanation / Answer

http://codepad.org/DOUKOKZ0 Note: I am note sure if your teacher wants you to compare just the 1st names in equal or the entire name, I did just 1st name, as it just seemed more correct, but otherwise the code would be: public boolean equals(Name n) { if(!((n.getFirstName()).equals(firstName))) return false; else if(!((n.getMiddleName()).equals(middleName))) return false; else if(!((n.getLastName()).equals(lastName))) return false; else return true; }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote