COMP 212 Lab 06: Containers

Quiz

Copy your code for the Hangman milestone 1, i.e., the AWord, ACharState, and associated concrete classes, into a new directory. (You should've fixed any bugs you had by now. If not, you should be fine for this quiz as long as the code follows the suggested UML diagram.)

Rewrite the code to use nested classes wherever appropriate. Make them anonymous inner classes wherever appropriate. Include a brief README describing only these changes to your code. To save yourself time and typing, use cut-and-paste in Emacs.

Turn in your resulting code using project name quiz1.

Containers

In class, we've discussed the IContainer interface:

     package containers;

     public interface IContainer {
        /**
         * If there is an object associated with key
         * then this object is returned else null is returned.
         */
        public Object find(Object key);

        /**
         * Afterwards, find(key) returns null, and if there is
         * an object associated with key then this object is
         * returned else null is returned.
         */
        public Object remove(Object key);

        /**
        * (key, value) is stored in this container with no
        * duplication and such that find(key) returns value.
        */
        public void insert(Object key, Object value);
     }
We also discussed one possible implementation using LRStructs. This source code is available here. There are many other possible implementations of this interface, e.g., we will later discuss ones using arrays and binary trees.

One of the important points of abstract data structures like these containers is that someone else can use your code knowing only that it matches the specified interface. You can change the underlying implementation to meet whatever needs are important, such as efficiency.

As an example, your job today is to write a implementation of IContainer using ALists. Use the provided code as a starting point to save typing. Be sure to hide any implementation details, such as the underlying AList, from any other users.