The first field of the record contains the person's
last name; the second field, the first name; the third, the social security
numer; and the fourth, the person's age. If the records are sorted on
the fourth field, the results would be:

We will call the entries in the records tokens.
One or more blanks separate the tokens from each other.
To enable your program to distinguish the tokens in a record,
use the StringTokenizer class (see page 274
in the text).

Here are the steps you should follow to write the program:

Write a
method public static void readArray( DataBase[] dv) that calls
readRecord to form the tokens from the record. DataBase
is a class given on the homepage consisting of an array of four fields which
are strings. In readArray,each record read is assigned to successive
elements of dv. Use the formulation given in Prog2 of
November 28 link. Note that the end-of-file corresponds to null
pointer so you may detect it in a while loop.

Write the method public static void readRecord line, DataBase
data). The string line is read in readArray (see
above) from the database file. The method uses the
StringTokenizer to assign the four tokens to an instance of the class
Database.

Note that you cannot print the elements of dv since they are
instances of Database and are thus pointers to the heap. You can,
however, print the fields of an element of dv. We do this in two
steps. public static void printArray(DataBase[] dv) calls
public static void printRecord(DataBase data) which prints the
fields of an element of dv, as we did in Prog2 of
November 28.

Finally, write public static void sort(Database[] array) which
sorts the array on a field indicated by the user. It is suggested that you use
the bubble sort which we studied in class. (See the Prog6.java on the Nov 21
class link) To compare two strings, use the compareTo method. If
string1 appears later than string2 in a dictionary, then string1.compareTo(
string2 ) > 0. If it appears before, then it is < 0.

Your program should sort on a key read by your program. Your program should be
robust throughout. If the key is out of range, your program should indicate
this. After the sort is done, your program should ask whether the user wants to
continue, just as in the craps game. If the user types any input other than y
or n, the program should inform him/her of the error and request new input.