Write a Java Application named HW2 (main class HW2, file HW2.java,
etc. etc. Consistent naming just makes it easier for me to grade
the things.)
The program is to prompt the user to type in a sequence of names, each
of which consists of a first and a last name. There should be a clear,
easy way for the user to indicate when the list of names is finished, e.g.
just hitting RETURN when asked for a first name. The program will
then print out various information about the list of names:
InputStream
s, BufferedReader
s, etc. because
you can use the InteractiveIO
class from chapter 4 to hide
all that; see the next hint.
InteractiveIO
class from chapter
4 of the textbook (which can be downloaded
from the class Web page). You may want to modify it (or better,
write a subclass of InteractiveIO
and put the
modifications in it).
Name
class as well,
allowing you to create Names, read them using an InteractiveIO object,
convert them to Strings for easy output, retrieve their first and last
names, and compare two of them in alphabetical order (as described
above, paying attention to the last name and only turning to the first
name if two last names are identical).
NameList
class (not
required, but might make HW3 easier), so (for example) the main program
doesn't even need to know whether you're using Vectors to store the
list. Use the class design recipe in the textbook to decide what
methods should be in this class.
Please type in a list of names. When you're done, just hit RETURN when asked for another name. First name? No first name. Do you want to enter a last name?no Thank you. Here's some information about that list of names. There were no names in the list.
Please type in a list of names. When you're done, just hit RETURN when asked for another name. First name?Stephen Last name?Bloch First name? No first name. Do you want to enter a last name?no Thank you. Here's some information about that list of names. The shortest first name was Stephen. The longest first name was Stephen. The average length of a first name was 7.0, and no first names were longer than that. The earliest name in alphabetical order was Stephen Bloch. The last name in alphabetical order was Stephen Bloch.
Please type in a list of names. When you're done, just hit RETURN when asked for another name. First name?Joe Last name?Schmoe First name?Stephen Last name?Bloch First name?Annie Last name?Schmoe First name?Edward Last name?Beeblebrox First name? No first name. Do you want to enter a last name?no Thank you. Here's some information about that list of names. The shortest first name was Joe. The longest first name was Stephen. The average length of a first name was 5.25, and 2 first names were longer than that. The earliest name in alphabetical order was Edward Beeblebrox. The last name in alphabetical order was Joe Schmoe.
Please type in a list of names. When you're done, just hit RETURN when asked for another name. First name?Billy Last name?Bob First name? No first name. Do you want to enter a last name?yes Last name?Somebodywithnofirstname First name?Jim Last name?Bob First name?Nolastname Last name? No last name. Do you want to use this name anyway?yes First name? No first name. Do you want to enter a last name?no Thank you. Here's some information about that list of names. The shortest first name was . The longest first name was Nolastname. The average length of a first name was 4.5, and 2 first names were longer than that. The earliest name in alphabetical order was Nolastname . The last name in alphabetical order was Somebodywithnofirstname.