Homework 4 - Dictionary
Due: Wednesday, July 21, 2010
This assignment asks you to implement three classes: Definition,
Dictionary, and DictionaryProgram. The Definition should capture
the relationship between a word and its meaning. The dicitonary
should provide the ability to add and lookup definitions. And, the
DictionaryProgram should provide the user interface. Details
can be found below.
The purpose of this exervise is to reinforce your understanding of
collections, especially those that are ordered and contain non-String
objects. It is also designed to give you some exercise with the
recently discussed filter idiom.
The Definition class
- This class should contain both a word and its meaning.
- Each of the word and the meaning should be initialized upon
construction and accessible thereafter.
- Since the meaning of a word can evolve over time, the meaning should
be changeable after initialization.
- Definition should be Comparable, this means implement the
Comparable interface and have the compareTo method, so that they can
The Dictionary class
- This class should contain a collection of
Definitions, implemented via an array of Definitions.
- It should be constructed empty with a maximum capcity as specified by
- Users should be able to add() Definitions, in which should be
kept in alphabetical order, in order to facilitate searching for
- It should be possible to, given a word, find its meaning (Hint: Create
an empty Definition and search for it). Start out with an
unordered list and a brute-force search, then sort the list, then
upgrade to binary serarch.
- The toString() method should return a String containing each and every
definition, in order, one per line.
- The beginsWith (...) method should accept a String, representing
the first characters of a word or words. It should return a
new Dictionary containing only those words from this Dictionary
that begin with these few characters. The returned Dictionary should
be ordered and, in every respect, a first-class Dictionary.
Hint: see the JavaDoc for the String class, lookup
- This class should include and make reasonable use of the
- This class should have a grow method
The DictionaryProgram class
- This class should contain a main() method that provides the user with
- The menu should allow the user to create a new Dictionary of
any size, add() words to the dictionary, and to find() and print a
Definition, given a word. Additionally, the user should be able
to print an alphabetized list of all words. And, of course, the user
should be able to exit the program.
- In the event of an error, a reasonable error message should be
- Strings are Comparable