Building Dictionary Implementations

Due Date: Sept 9, 2008

This project tests your basic programming ability, your ability to code in Java (or how fast you can learn Java), your knowledge of simple data structures and algorithms, and how well you can read and follow instructions. This project is a typical undergraduate project, but with a shorter deadline. If this project is not easy for you, this course may overwhelm you. This project is a good way for us to get to know each other. :)

Your goal is to produce two simple Java implementations of a Dictionary interface, LinkedListDictionary and HashDictionary, that map a String key to an Object value. You should test your your code well including all boundary conditions as you will not see the test harness I will use to check out your project.

You must implement this project successfully without knowing precisely how I will test it. There are two reasons:

This project is primarily meant to test your basic Java skills:

If you do not know how to implement a hash table or linked list, you must learn this outside of class; either by reading or talking to friends.

IMPORTANT: You are to actually implement a hashtable and linked list, not simply wrap Java's existing java.util.Hashtable and java.util.LinkedList classes (or HashMap, etc...). In fact, you must not reference these classes at all.

Project details

You are to build at least two Java classes called LinkedListDictionary and HashDictionary, which must implement the Dictionary interface:

package dict;

public interface Dictionary {
  /** Add an object to the dictionary.  Do not allow null keys or values.
      Do nothing upon invalid key or value.
      put() may be called with the same key multiple times; you do not
      have to collate these values in a list and associate with a single
      key.  Just keep adding key/value pairs to the appropriate buckets.
      Add objects to any linked lists at the end of the list to preserve
      order of addition.
   */
  public void put(String key, Object value);

  /** Delete the first object you find associated with key from
   *  dictionary and return it.  Return null if not found.
   */
  public Object remove(String key);

  /** Return the first value object you find associated with key from
   *  dictionary; return null if not found.
   */
   public Object get(String key);

  /** Return a string of the key/value pairs in the dictionary.
      The string should look EXACTLY like this for both implementations:

        [key1:value1, ..., keyN:valueN]

      If there are multiple values with the same key, list the key
      multiple times.
      The element separator is ", " (comma space) and there NO newline
      character as I will print that myself during testing.  I will be
      automatically testing your projects!
   */
   public String toString();
}

Please include this interface dict.Dictionary in the jar file you submit.

Requirements

Submission

You will create a jar file called dict.jar containing source and *.class files and place in your lib directory:

https://www/svn/userid/cs601/dictionary/trunk/lib

To jar your stuff up, you will "cd" to the directory containing the dict subdirectory and create the jar in the lib dir:

cd ~/cs601/dictionary/trunk/src
jar cvf ~/cs601/dictionary/trunk/lib/dict.jar dict

You will see something like this:

adding: META-INF/ (in=0) (out=0) (stored 0%)
adding: META-INF/MANIFEST.MF (in=56) (out=56) (stored 0%)
adding: dict/ (in=0) (out=0) (stored 0%)
adding: dict/Dictionary.class (in=309) (out=189) (deflated 38%)
adding: dict/Dictionary.java (in=418) (out=200) (deflated 52%)
40%)
adding: dict/HashDictionary.class (in=2820) (out=1470) (deflated 47%)
adding: dict/HashDictionary.java (in=2434) (out=722) (deflated 70%)
adding: dict/LinkedListDictionary.class (in=1778) (out=954) (deflated
46%)
adding: dict/LinkedListDictionary.java (in=1362) (out=490) (deflated
64%)
adding: dict/timestamp.inf (in=394) (out=141) (deflated 64%)
etc...
Total:
------
(in = 29765) (out = 10864) (deflated 63%)

The jar will contain .java and .class files as well as any other file you have in there; be careful not to store your personal diary in there <wink>. You should test your project by running as I will run it per the Grading section below.

Please bring a print out of each java file in your project including your test harness.

Grading

I will run your program by pulling your dict.jar file from the repository and running like this:

java -cp .:dict.jar TerenceTestDictionary

It will launch my TerenceTestDictionary.main() method, which will dynamically load your classes (dict.HashDictionary, dict.LinkedListDictionary) from your submitted jar file. Note that you should include interface dict.Dictionary in the jar.

My test harness exercising your implementations of the dict.Dictionary interface will be of the form:

import dict.*;

public class MyTestDictionary {
  public static void main(String[] args) {
    HashDictionary hd = new HashDictionary();
    LinkedListDictionary lld = new LinkedListDictionary();
    // Dictionary d = hd; // test hash dictionary
    Dictionary d = lld;   // test linked list dictionary
    d.put("Terence", "parrt@cs.usfca.edu");
    System.out.println(d);// calls toString()
    ...
  }
}

You may discuss this project in its generality with anybody you want and may look at any code on the internet except for a classmate's code. You should physically code this project completely yourself but can use all the help you find other than cutting-n-pasting or looking at code from a classmate or other Human being.

Your grade is a floating point number from 0..10.