Go!
We are again providing some JUnit tests to help you assess whether your code is performing correctly. You will need to define a class and several methods to work with these JUnit tests. You MUST use the method names given below. If you do not the JUnit tests will not compile and run correctly. You may NOT change the JUnit tests.
Step 1: read words from a file
A list of possible words will be read from a file. In lab 8 the word file is pretty small (just 260 words). By the time the game is finished we will use a free open-source word list with over 113,000 words.
Because words with seven letters will be used as starting points for the list of words to be found in each round of the game, it turns out it will be convenient to keep the seven letter words in a separate data structure.
In the code package, we have given you a little bit of a start on the Model class, to ensure that JUnit testing runs smoothly. We have defined the Model with two instance variables, one of type HashSet< String> and one of type ArrayList< String>.These two collections will be used to store words that your program reads from a file, the former for possible 'guess' words and the latter for seven-letter reference words. We have also provided one constructor for the class, that allows a Model to be associated with a specific HashSet and ArrayList of words.
Define a second constructor for the Model class with just a single String parameter (this will be the name of file containing the word list) that properly initializes the two instance variables, and then calls a method (see next paragraph) to read the contents of a file, passing along the value of the constructor's parameter as argument.
Next, define the method to read words from a file and populate the two data structures (the ArrayList and the HashSet). Add the words that are of length 7 into the ArrayList, and the words of length less than 7 into the HashSet.
To make reading from a file a little easier we are providing you with the class CSE115FileReader. This class defines an Iterator
If you create a CSE115FileReader with the name of a non-existent file then hasNext() will always return false and next() will always return null.
Step 2: String as a sequence of Characters
Define a method that takes a String as an argument and returns an ArrayList
This is independent of step 1. You must name this method string2charList.
Step 3: Is String made up of letters in ArrayList< Character>?
Define a method that takes a String and an ArrayList< Character> as arguments, and returns true if the all of the characters of the String appear in the ArrayList, and false otherwise.
For example, if the ArrayList
This is independent of steps 1 and 2. You must name this method anagramOfLetterSubset.
Step 4: Create a HashSet< String> of all the words that can be formed from the letters in a String
Define a method that takes a String as an argument a returns a HashSet
This method relies on the word list having been set up in the constructor (step 1), and uses the methods defined in steps 2 and 3. You must name this method possibleWords.