Write an interface Directory to manipulate entries in a telephone directory for the
University. The interface must support the following operations:
1) The ability to insert new entries into the directory. Entries should be stored in
alphabetical order of surname.
2) Delete entries from the directory either by name or number
3) Provide a lookup method that will find the extension no of a member of staff given
his/her name. You should try to make this method run as efficiently as possible.
4) Change a person’s telephone number
5) Print the telephone directory in a neatly tabulated fashion.
Write a class ArrayDirectory that implements this interface using an array to store the
telephone directory information. The class must store the surname and initial for each
member of staff and their telephone extension (a four digit number which may start with a
zero). You may find it useful to define a class Entry to store information about individual
entries. The entries should be read into the array from a text file consisting of multiple lines
in the following format:
Surname<tab>Initials<tab>Telephone extension
Write a main program that reads in data from a file and then tests all the methods of your
class interface. Note it is not necessary to write data back to disk (even if it has changed) in
this project.
For data insertion and lookup, you should measure the performance for the average case (e.g.
looking up a record in the middle of the data). To do this you can use the static method
System.currentTimeMillis() which returns the time in milliseconds. To get an
accurate measure of the time to perform an operation it is a good idea to perform each
operation 1000 (or even 10000) times and measure the time taken. This will remove any problems due to the system clock having a coarse granularity (not ticking very often).
Make sure you only time the method and not any input/output associated with it. Your
documentation should include a discussion of these results.
Part 2
You decide that your solution to part 1 may be too slow to be useful when used with a real
large telephone directory and make the following changes to attempt to improve the
performance of your program:
1). Provide a second implementation (ListDirectory) of the Directory interface
using the Java Collections List interface and LinkedList classes.
2). The changes in 1) should make adding, deleting and modifying records more efficient
but will probably reduce the time to lookup numbers. To overcome this you use a technique
called hashing. Instead of storing all the records on one list you use a series of lists. The data
for all people whose surname begins with ‘A’ is stored on the first list, records for all people
whose surname begins with ‘B’ on a second list and so on. Write a third implementation
(HashDirectory) of the Directory interface using this technique.
Again, you should measure the performance for the best, worst and average cases of
implementations 1) and 2) above. Compare the efficiency of each of the 3 implementations in
your documentation.
Part 3
Choose one of your 3 implementations from Parts 1 and 2 and embed it in a graphical user
interface that allows users to perform all the methods in the Directory interface using a mouse
and keyboard appropriately.