CompSci 100E, Fall 2006, Anagram

Anagrams

Two words are anagrams if they contain the same letters. For example, bagel and gable are anagrams as are glare, lager, large, and regal.

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.


AnagramModel.java

Snarf the assignment using Anagram.jar. This includes files containing the needed daata.
You're given a program AnagramModel.java whose 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.

gui

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.

  1. No input/text box should appear in the GUI -- see the screen shot below.

  2. Running the program should display in the GUI/output a list of all anagrams in the file loaded in the model. The user will not be prompted for a word as in the current version. Instead, after reading a file, the anagrams in the file are to be displayed in the GUI/view.

    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.

  3. The simplest method for implementing this modification involves sorting an array/ArrayList of 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.

gui

Implemetation Details

Create 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.
  1. 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).

  2. process should do nothing, except perhaps send a message to the views indicating that this version doesn't process single words.
  3. 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).
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.

Implementation Hint

Create an ArrayList of strings where each string is a sequence of anagrams of each other, separated by one space. These strings will then be displayed in the GUI/output window. To find the anagrams, sort the collection of 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.

Full/Extra Credit

Without doing this option the maximal grade on the assignment is the equivalent of an A-.

For A/A+/Extra credit the anagrams should be displayed in a particular order.

  1. Words in each sequence should appear in alphabetical order.
  2. The longest sequence (number of anagram-words) of anagrams should be printed last, the shortest --- length two --- sequences should be printed first.
  3. In sequences that have the same number of anagrams print sequences in order by word length: two-letter word sequences appear before three-letter word sequences.
  4. In sequences of the same length with the same number of letters in each anagram the sequences are ordered alphabetically by the first word in the sequence.
You should create a private/nested Comparator class and use this to sort the sequence of anagrams that are printed.

Grading

This program is worth 25 points.

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.

Submit

To submit use Eclipse and the name anagram.