+------------------------+ | +--------------------+ | | | | | | +--------------------+ | | | | | | FIND CLEAR | +------------------------+The user enters a word, e.g., bee, presses FIND, and the application returns a one-line definition:
+------------------------+ | +--------------------+ | | | bee | | | +--------------------+ | | | | n. A winged insect that gathers nectar and pollen | | | | FIND CLEAR | +------------------------+
When pressed, the CLEAR button erases both the text field and label. When the user attempts to locate a word that is not contained in the dictionary, an appropriate error message is printed.
Initializing the application: The application's dictionary will be stored in a hash table. In concept, each hash-table entry consists of a word (the key) and its definition (a string), but you must also be prepared to process collisions.
When the application is started, it reads a sequential text file that contains the words and their definitions. The data is loaded into the hash table, and then the application constructs and displays its User Interface to the human user. Construct the application so that the sequential file is given as a program argument in the startup command:
java Dictionary.Start defn.txt
starts the application and tells it to find its data in the text file,
defn.txt.
The format for the sequential file consists of pairs of text lines; the first line of each pair lists a word, and the second line gives the word's definition. Here is an example of a file with four such pairs:
bee n. A winged insect that gathers nectar and pollen bear n. An investor who sells stock shares in expectation that prices will fall hairy adj. Covered with hair be v. To exist: ``I think, therefore I am'' (Descartes)It does not matter whether or not the words in the file are sorted; this is one of the beauties of hash coding---sorting is unneeded.
It is important that your hash table handle collisions correctly. To test this, construct a small hash table, say, of size 5, and read an input file that contains 6 words and their definitions---your application must operate correctly. Also test your program with a more suitable arrangement, e.g., a table of size 17 and an input file of 6 words.
Improving the application: Once the basic application is operating properly, then you must improve it so that it can save multiple definitions for the same word. Here is the format of sequential file that your application must use:
bee n. A winged insect that gathers nectar and pollen bear n. An investor who sells stock shares in expectation that prices will fall hairy adj. Covered with hair be v. To exist: ``I think, therefore I am'' (Descartes) bear n. A large mammal having a shaggy coat and a short tail bear v. To carry or supportWhen the user asks for the definition of, say, bear, all three definitions are retrieved and displayed. (You might alter the User Interface so that it displays the multiple definitions within message dialogs or within a helper frame --- do as you choose.)
Implementation and submission requirements: You must organize your application into multiple classes, in the usual Model-View-Controller architecture. Of course, you must write a class HashTable that holds the array of words-with-definitions. Also, you must write your own hash function; use the polynomial-coding method. (You may not use the built-in hash function in the Java library.)
Document all classes and package them accordingly. Run javadoc on your completed program. Your application must include a package named Dictionary that contains a Start class, so that the Teaching Assignment can execute your program. Supply a suitable sequential file that contains words and their definitions for testing. (The Teaching Assistant will try your test data as well as her own.) Submit your Assign7.jar file at http://www.cis.ksu.edu/classes/300/Assign/submit.html.