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. Its constructor takes a String as an argument; the String is the name of the file whose contents the iterator will read. The iterator's next() method returns the next unread line from the file; its hasNext() method returns false when there are no more lines in the file to visit.

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 that contains the characters of the String, in the same order.

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 contains the letters from "smooths" (i.e. 's', 'm', 'o', 'o', 't', 'h', and another 's') then "toss" should yield true (since there is one 't', one 'o', and two 's' characters in the ArrayList. However, "moms" should yield false because there are not two 'm' characters in 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 of all the words from the word list that are of length 3, 4, 5, or 6 and can be made from the letters in the argument.

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.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.