CS 2102 - Dterm 10

Homework 5 - Abstracting over Behavior

Due: Tuesday, April 13 at 5pm

Assignment Goals

Assignment

I love doing crossword puzzles. Some crossword puzzles have a theme, where many of the answers to the given clues are related to the often cryptically-named theme; the themes for the puzzles in the last two weeks of the Sunday Boston Globe have been "By the Numbers", and "Nice Work". In this homework, you'll represent lists of crossword puzzles, where each puzzle has a theme, a number of clues in the across direction, a number of clues in the down direction, and a level of difficulty ("easy", "medium", or "difficult").

Problems

  1. Create a list hierarchy to represent a list of Crosswords, as indicated in the following class diagram. Create examples of lists of Crosswords.
              +----------------------------------+                
              |  ILoCross                        |<--+                   
              +----------------------------------+   |
                             |                       |
                            / \                      |
                            ---                      |
                             |                       |
               ---------------------------           |
               |                         |           |
      +----------------+     +-------------------+   |
      | MtLoCross      |     | ConsLoCross       |   |
      +----------------+     +-------------------+   |
      +----------------+  +--| Crossword  first  |   |
                          |  | ILoCross rest     |---+  
                          |  +-------------------+ 
                          v	           
                    +---------------+    
                    | Crossword     |    
                    +---------------+    
                    | String theme  |     
                    | int across    |      
                    | int down      |      
                    | String level  |      
                    +---------------+    
    

  2. Add the following interface to your project:
    public interface ISelectCrossword {
    	/* Return true if the given Crossword should be selected */
    	public boolean select(Crossword c);
    }
    
    Create a class that implements ISelectCrossword. The criterion for selection is that the total number of clues in the given Crossword is less than 300. Make sure you provide tests for your class.

  3. Design the method allLessThan300 that determines if all the crosswords in this list have fewer than 300 clues. The method should take as an argument an instance of the class you created in Problem 2. Test.

  4. Now we want to determine if the string "WPI" occurs anywhere in the theme for a given Crossword. Design the class ThemeIncludesWPI that implements the ISelectCrossword interface with an appropriate predicate method. (Hint: look at the Javadoc for the String class to determine if a String contains a specified substring). Test.

  5. Design the method anyContainWPI that determines if any of the Crosswords in this list have themes with the string "WPI" in them. Test.

  6. Design the method allSuchCrosswords that determines whether all Crosswords in a list satisfy the predicate defined by the given instance of an ISelectCrossword. Provide test cases for allSuchCrosswords that determine if all the Crosswords in a list have fewer than 300 clues, and if all the Crosswords in a list have themes with the string "WPI".

  7. Design the class GivenDifficulty that implements the ISelectCrossword interface with a method that returns true for all Crosswords that are of a given level of difficulty. The desired level is provided as a parameter to the constructor, and so is specified when a new instance of the class GivenDifficulty is created. Test.

  8. Design the method filter that produces a list of only those crosswords that satisfy the given predicate. Write test cases for filter that filter lists to produce lists of crosswords with fewer than 300 clues, lists of crosswords with "WPI" in the theme name, lists of difficult crosswords, and lists of easy crosswords.

What to Turn In

Create an archive of your Eclipse project. Using web-based turnin, turn in a single zip file containing all code and documentation for this assignment. Follow the naming conventions when naming your file.