The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Interface task

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.

Re: Interface task

Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for newcomers.

What you've posted is known as a "homework dump." If you do not exhibit some effort and/or ask specific questions (Please, something other than "I don't know where to start.") about what you need help with, this thread will be locked, and you will be invited to try again.