Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Download the attached Name.java file and add the equals() method from segment C.24 page 917. #14. If sue and susan are two instances of the
Download the attached Name.java file and add the equals() method from segment C.24 page 917.
#14. If sue and susan are two instances of the class Name, what if() statement can decide whether they represent the same name?
Write a Java program to do this with JavaDoc. Instead of sue and susan use variables name0 as your name, name1 as "Mr." "Reed", and name2 as your name again. Then test for equal names as follows:
- your name equals my name (Mr. Reed) // name0.equals( name1 )
- your name equals your name // name0.equals( name2 )
- your name == your name // name0 == name2
Attach the updated Name.java, the lab program, and copyAndPasted output. SR
Attached file
/** A class that represents a person's name. Listing B-1 in Segment B.16 of Appendix B. @author Frank M. Carrano @author Timothy M. Henry @version 5.0 */ public class Name //implements Comparable{ private String first; // First name private String last; // Last name public Name() { } // end default constructor public Name(String firstName, String lastName) { first = firstName; last = lastName; } // end constructor public void setName(String firstName, String lastName) { setFirst(firstName); setLast(lastName); } // end setName public String getName() { return toString(); } // end getName public void setFirst(String firstName) { first = firstName; } // end setFirst public String getFirst() { return first; } // end getFirst public void setLast(String lastName) { last = lastName; } // end setLast public String getLast() { return last; } // end getLast public void giveLastNameTo(Name aName) { aName.setLast(last); } // end giveLastNameTo public String toString() { return first + " " + last; } // end toString } // end Name
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started