CSCI 220
Assigned Date: Monday, October 27, 2003
Due Date: Tuesday, November 4, 2003
Due Time: Noon



This assignment focuses on methods, modularization, Strings, arrays, and sorting.

Source filename to be submitted:



See instructions in the first homework 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 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.)



Two ordered lists of the names, in the format lastname, firstname.  (A comma and single space separates the last and first names.)



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 to read individual characters into character arrays and then build your strings from the character array.

You should, at least, have the following methods:

  1. inputNames() accepts two arrays as parameters and populates them from the input.
  2. sortNames() accepts the name arrays as parameters and sorts them in lexicographical order.
  3. outputNames() accepts the name arrays as parameters and outputs them.

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)


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)



<your program produces no output>


  1. Follow the above I/O format carefully.
  2. Test your program with different inputs to make sure it works properly.



See instructions in the first homework assignment.