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.
For example, here's a list of words such that the words on each line are anagrams of each other:
bared beard bread debar debra abel able bale bela elba bares baser bears braes saber abets baste bates beast beats caster caters crates reacts recast traces caret cater crate react recta traceHere's another list such that the words on each line are texting-equivalent anagrams, that is you'd press the same sequence of keys on a cell-phone keypad to text the words on each line (the key-sequence is shown with the words):
11626 acres bards barer bares baser bases caper capes cards cares cases 1166 barr bars bass caps carp carr cars 116726 barter bastes carter carver carves caster castes 3552 gone good goof home hone hood hoof 35526 goner goods goofs homer homes honer hones hoods hoofs innerIn this program you'll be working to understand tradeoffs in determining how words are anagrams and in how object-oriented programs are constructed using what's called a model view pattern (sometimes called model, view, controller).
The program has two parts, you should complete Part I before moving onto Part II, and you should submit your code/solutions for each part separately as indicated below.
www.cs.duke.edu/courses/spring06/cps100/snarf
which you
can enter by right-clicking in the snarf-site browser window of Eclipse.
The program SimpleAnagram.java launches the model and view that together comprise the program you'll be running. Initially the program reads a dictionary of words (you can read your own dictionary too) and prints the anagrams of the word typed into the textbox, which is pots in the screenshot below.
There are other classes and interfaces that you'll need to understand, but for Part I 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 goals of part I of this assignment are
process
method finds all strings in a file that are
anagrams of the String
object passed to the
process
method. The GUI class SimpleViewer is the view for
this program --- it interacts with the user, but the intelligence and
state of the program are part of the model, not part of the view. The
user enters a word in the GUI, which is then passed to the model. The
model finds the anagrams and displays them in the view.
For Part I you'll change the launching/main program SimpleAnagram.java so that the GUI
has no text box for a word. You'll also create a new model
class with a different functionality as part of its process
method --- it results in all anagrams in a file of words being displayed
in the GUI. In summary, for the new program
The program reads one file, and finds the words in that file that are anagrams of each other.
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.txt.
In the view, each collection or 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.
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.
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 setWords
is called, the views will display all anagrams (call
notifyViews
appropriately) and a message about the number
of anagrams should be displayed (call messageViews
appropriately). Note: setWords
is called
from initialize
--- your view should call
initialize
.
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).
Anaword
objects. Then all anagrams will be contiguous in the sorted list.
You'll need to modify the code in 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. Construct a new ArrayList of
strings that will be passed to the view, each string is one sequence
of anagrams, formed by concatenating the string representations of
words that are anagrams.
AllAnagramModel
. Specifically,
your program should not take more than around a minute to display
process a 40,000 word file like lowerwords.txt.
For A/A+/Extra credit the anagrams should be displayed in a particular order.
You should create a private/nested 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
The extra credit is worth 12 points, basically three points for each of the four parts.