Word puzzles like the Jumble shown below, and found in many newspapers are based on anagrams too. You can also play jumbles online at jumble.com.
process method finds all strings in a file
that are anagrams of the String object passed to
the process method. The anagrams are displayed in
the GUI/view
(whose code is found in SimpleViewer.java)
associated with the model. The screen-shot below shows the GUI
after it has displayed some anagrams.
As the source of anagrams, the program uses a dictionary/file specified
when it's started, or you can load a file of words. The words are
loaded using the model's initialize method (which you'll
see simply calls the setWords method.)
The program SimpleAnagram.java launches the model and view that together comprise the program you'll be running. There are other classes and interfaces that you may need to understand, but you'll be creating a new subclass of AnagramModel.java and then using that from the SimpleAnagram.java launch/run code (you'll need to modify the launch/run code).
The new functionality should result in changed behavior of the GUI as follows.
The program reads one file, and finds the words in that file that are anagrams of each other.
Each sequence of anagrams is displayed on one line, and every line displayed should have at least two words that are anagrams. For example, the output of the program might be as follows (depending on the file read). Do not print lines with only one words, e.g., for the word "zoo" which doesn't have any anagrams.
gazer graze gases sages heals leash shale heaps phase shape hares hears share shear earth hater heart haste hates heats haves shave arise raise lakes leaks
Be sure that every line printed consists of words that
are anagrams of each other and that every line printed
has at least two words on it.
Anaword
objects. Then all anagrams will be contiguous in the sorted list.
Here's a screen shot showing the last few anagrams printed when the extra-credit option is used (see below) from the file words.lower.
AllAnagramModel as a subclass of
AnagramModel. You'll need to implement the following
methods in the subclass you create, and perhaps any helper methods these
require.
setWords which in the code you write will process all
the words read and then notify the views appropriately so that
the views display all the anagrams.
When called, the views will display all anagrams (call
notifyViews appropriately) and a message about the number
of anagrams should be displayed (call messageViews
appropriately).
process should do nothing, except perhaps send a
message to the views indicating that this version doesn't process single
words.
constructor for the subclass may need to initialize
state --- note that parent-class consructor will be called automatically
if your constructor has no parameters (default constructor).
SimpleAnagram so that an
AllAnagramModel object is created. You'll need to modify
the call that constructs the SimpleViewer object so that
the title of the GUI changes and so that an empty string "" is
passed as the label for the input box which results in no input box.
Note: you'll run SimpleAnagram, but your
modified code is the new model used by that code.
Anaword objects, then run through looking for
equal elements, these are anagrams. Build the string of potential
anagrams as you go, or create an array/arraylist and build the strings
from that.
For A/A+/Extra credit the anagrams should be displayed in a particular order.
Comparator class and use
this to sort the sequence of anagrams that are printed.
| Criteria | Points |
|---|---|
| Implemented as specified in general | 10 |
| Robust for all inputs/special cases | 6 |
| Documentation, style of code | 5 |
| README | 4 |
In your README, which you must submit, you should include