CSCI 220
HOMEWORK ASSIGNMENT #5
Assigned Date: Monday,
October 27, 2003
Due Date: Tuesday, November 4, 2003
Due Time: Noon
Purpose:
This assignment focuses on methods, modularization, Strings, arrays, and sorting.
Source filename to be submitted: SortNames.java
Documentation:
See instructions in the first homework assignment.
Assignment:
Write a program that sorts a list of names alphabetically. That is, given a list of names (first and last names), it produces a listing of the names ordered lexicographically (by last name and then by first name).
Input:
Input comes from the standard input. It consists of a number indicating how many names will be provided, then the list of first and last names, one first-last pair per line, in the format: firstname lastname. (A single space separate the first and last names.)
Output:
Two ordered lists of the names, in the format lastname, firstname. (A comma and single space separates the last and first names.)
Specifics:
Input names into two parallel arrays of String. One array holds first names and one last names. Modify the selection sort given in Example 5-3 (page 155 in textbook) to work with arrays of strings. (Hint use "compareTo" string method – see page 321 in textbook.) You may use StdIn’s readString() method to input full names into a String variable and then pull names apart to store into separate arrays; or use System.in.read() to read individual characters into character arrays and then build your strings from the character array.
You should, at least, have the following methods:
These methods should be documented as per instructions in class (purpose, preconditions, postconditions, parameter data flow (in, out, in/out)).
Sample Run 1: (user input in italics)
6
Tom Jones
Meredith Franklin
Alice Brady
Robert Spencer
Katelin Hudson
Jane Jones
Brady, Alice
Franklin, Meredith
Hudson, Katelin
Jones, Jane
Jones, Tom
Spencer, Robert
Sample Run 2: (user input in italics)
0
<your program produces no output>
Notes:
Submission:
See instructions in the first homework assignment.