Back to 211 Main Page

Mobius strip

Assignment 2

Submission

  • Email your assignment to ztomasze@hawaii.edu.
  • Attach the source code to your email. Send me only the source code (.java files); do not include the .class or any other files. Do not zip or otherwise bundle the .java files.

Requirements

As stated on the assignment handout, you must:

  • Use a linked list data structure to store entries in the directory. [Reuse KWLinkedList for this.]
  • The entries must be kept ordered by name. [This ordering work should be done in the directory. Do not change KWLinkedList to do the ordering. "Show Directory" in your UI should show the list to the user in its ordered state.]
  • You may not have duplicate entries (having both the same name and the same number) in the list. [But you should allow multiple entries with the same name and different numbers.]
  • Remove will thus have to ask for both the name and the number of the entry to delete. [You will need to implement a remove method in KWLinkedList.]
  • (Looking up an entry should return all numbers for the given name.)

Suggestions

As long as you meet the requirements above, you can do this assignment however you want. However, here are some of my suggestions to help if you're stuck.

As you change Assignment 1, here's what changes you'll need to make for each class:

PDApplication; PDUserInterface
Do not change.
DirectoryEntry
You do not need to change this. However, here is a copy of my DirectoryEntry that you can use. This version includes a toString, equals, and compareTo method, which can make your life easier.
KWLinkedList
Use the version from the textbook zip file, which is the same as the code in the lecture handout. Here is a version that will immediately compile. Although you can leave the set method as it is, you must still implement a remove method. This can be the remove method of the list, the iterator, or (preferably) both.

If you implement remove in the iterator, you can use this driver to test it. (Make sure you have the corrected hasPrevious method, available in the version of KWLinkedList above.)

PhoneDirectory
You will need to change a few of the method signatures in this file. Here is a version with the changes I'd recommend. Read the Javadoc comments to see what each method should do.
ListBasedPD (formerly ArrayBasedPD)
This should still implement the PhoneDirectory interface, as ArrayBasedPD did. You'll need to make a number of changes.

Instead of a DirectoryEntry[], you will use a KWLinkedList. So you can remove the size and capacity variables. The following methods will need to be changed to reflect this change in underlying data structure:

  • addOrChangeEntry, reallocate, find -- just remove these.
  • add -- make this public, rename to addEntry and change it to work with a linked list. Remember to keep the elements ordered as you add!

    Remember, the list does not accept duplicate items. The easiest way to handle this is to change the return type to boolean (which is what my new PhoneDirectory interface assumes). Return true if you successfully add an item. If a duplicate entry already exists in the list (both name and number match the item being added), do not add the new entry, and return false instead.

    The alternative to returning a boolean is to instead throw an exception when a duplicate is encountered.

  • toString -- make this method that returns a String representation of the list. (You probably already did this for Assignment 1, though you may have called the method something different.) Once you have add and toString written, you can start testing you class.
  • lookupEntry -- I have this returning a String[] of all the numbers for a given name, but this is hard to do correctly. (You can change this to return a String containing all the data you need if you're stuck.)
  • removeEntry -- relatively easy to do if you have a remove method for the KWListIter.
  • loadData -- just change the call to add to addEntry
  • save -- change this to work with a linked list.

You should now have the four methods specified by the PhoneDirectory interface, plus toString. (If you need any other private helper methods, that's fine. But don't leave old code around that doesn't do anything.)

If you implement your ListBasedPD this way, you will be able to use the following driver I wrote to test my own program. This does some basic testing of the five methods. (It may not catch certain errors with your remove.)

PDConsolueUI and PDGUI
Change these to ask for the required input, and return the appropriate feedback.

Grading:

This assignment has been extended to give you time to adequetly test and correct your code. Use the two drivers provided above to test KWLinkedList and ListBasedPD. You may need to modify the drivers if you are following a different interface; otherwise, you can write your own driver, or just carefully test your program using the user interface. (As always, let me know if you have any questions.) Be sure that you meet the following requirements.

Out of 100 points:

10 - Compiles
10 - Uses KWLinkedList to store entries.
10 - KWLinkedList's (and/or its iterator's) remove method has been correctly implemented.
15 - The list is kept ordered by name.
This ordering work should be done in the directory (not in KWLinkedList).
10 - The program allows users to add entries.
The list does not allow duplicate entries. The program should let the user know if they tried to add a duplicate entry
10 - The program allows users to remove entries.
It should let them know if they try to remove a non-existant entry.
10 - The program allows users to lookup entries.
This should return all matching numbers for the given name.
15 - The program allows users to see the current, ordered contents of the directory.
5 - Save and load works correctly.
5 - Program can run either in console or GUI mode.


~ztomasze Index : TA Details: ICS211: Assignment 2
http://www2.hawaii.edu/~ztomasze
Last Edited: 26 Sep 2006
©2006 by Z. Tomaszewski.