CSCI 151 Lab 4: Vector and Dictionary


Overview

This lab will give you more experience working with Vectors, and experience working at multiple levels of abstraction. We will start by improving our Vector class, and then use our improved Vectors to create a better Dictionary.

Materials

Setup

Part 1: extending Vector

Your first assignment is to add more useful methods to Vector. In particular, you should add each of the following methods:

Hint: your implementation of find should only be one or two lines long, if you make use of indexOf.

Part 2: Equality for Associations

In order to effectively look up an Association in a Dictionary, we will want to be able to compare two Associations, so we will also implement equals for them. However, we are going to do something a bit strange and just compare their keys, not their values. If we were just implementing a generic class for pairs, this would be the wrong thing to do. However, Associations are not just generic pairs: we are going to use them to store key-value associations, to implement things like dictionaries. In a key-value association, we always look things up by key, so it makes sense to only compare Associations by key.

Part 3: A better dictionary

Finally, we will use the improved Vector and Association classes to build a better Dictionary.

What to Hand In

You should turn in

Grading