Question: Download the attached files into DrJava: NameInterface.java, Name.java, Driver.java Run the client Driver . Add your name and Mr. Reed to the main() . Then
- Download the attached files into DrJava: NameInterface.java, Name.java, Driver.java
- Run the client Driver.
- Add your name and Mr. Reed to the main(). Then println() them at the end of main().
- Attach the client Driver. CopyAndPaste the compiler output window.
NameInterface.java
/** An interface for a class of names. Listing P-2 in Segment P.15 of the Prelude. @author Frank M. Carrano @author Timothy M. Henry @version 5.0 */ public interface NameInterface { /** Sets the first and last names. @param firstName A string that is the desired first name. @param lastName A string that is the desired last name. */ public void setName(String firstName, String lastName); /** Gets the full name. @return A string containing the first and last names. */ public String getName(); /** Sets the first name. @param firstName A string that is the desired first name. */ public void setFirst(String firstName); /** Gets the first name. @return A string containing the first name. */ public String getFirst(); /** Sets the last name. @param lastName A string that is the desired last name. */ public void setLast(String lastName); /** Gets the last name. @return A string containing the last name. */ public String getLast(); /** Changes the last name of the given Name object to the last name of this Name object. @param aName A given Name object whose last name is to be changed. */ public void giveLastNameTo(NameInterface aName); /** Gets the full name. @return A string containing the first and last names. */ public String toString(); public boolean equals( Name newName ); } // end NameInterface
Name.java
/** A class that represents a person's name. The class in Listing B-1 in Segment B.16 of Appendix B, but modified to use and interface. NOTE the change to the parameter in the method giveLastNameTo. @author Frank M. Carrano @author Timothy M. Henry @version 5.0 */ public class Name implements NameInterface { 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(NameInterface aName) { aName.setLast(last); } // end giveLastNameTo public String toString() { return first + " " + last; } // end toString } // end Name
Driver.java
import java.util.*; /** A driver that demonstrates the class Name and the interface NameInterface. @author Frank M. Carrano @author Timothy M. Henry @version 5.0 */ public class Driver { public static void main(String[] args) { NameInterface jamie = new Name("Jamie", "Jones"); NameInterface jane = new Name(); jane.setFirst("Jane"); jane.setLast("Doe"); System.out.println("Here are two names: "); System.out.println(jamie); System.out.println(jane); System.out.println("Jamie Jones adopts Jill Doe and changes Jill's last name:"); jamie.giveLastNameTo(jane); System.out.println("After name change: "); System.out.println(jamie); System.out.println(jane); System.out.println(" Let jamie and friend be aliases. "); NameInterface friend = jamie; System.out.println(" Change jamie's last name to Smith: "); jamie.setLast("Smith"); System.out.println(jamie); System.out.println(" Here is friend's last name: "); System.out.println(friend.getLast()); System.out.println("Testing aliases:"); if (jamie == friend) System.out.println("friend and jamie are aliases" ); else System.out.println("friend and jamie are NOT aliases" ); System.out.println(" Done."); } // end main } // end Driver /* Here are two names: Jamie Jones Jane Doe Jamie Jones adopts Jill Doe and changes Jill's last name: After name change: Jamie Jones Jane Jones Let jamie and friend be aliases. Change jamie's last name to Smith: Jamie Smith Here is friend's last name: Smith Testing aliases: friend and jamie are aliases Done. */ Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
