I dont know how to start The first step and confused about step 4
CSE115 Lab 8
Tuesday recitations: 9:00 PM on 4/4
Wednesday recitations: 9:00 PM on 4/5
Thursday recitations: 9:00 PM on 4/6
Friday recitations: 9:00 PM on 4/7
This lab is the first of three labs that all together have you build a version of the game TextTwist2.
TextTwist2 is a game in which you create words from the letters of a seven-letter word. For
example, if we pick "smooths" as our reference word we can form words such as "moth", "moths",
"moot", "soot", "hot", "toss", etc.
There are several websites where you can play this game, including:
You can probably find others. Read the instructions for the game, and try it out, so you have a
better understanding of what you're aiming for. Our rules may be a little different in the end, so
don't get too hung up on the specific rules (especially if you look at several different websites).
You will build part of the functionality of the game in this lab (lab 8), tackle a bit more in lab 10,
and finish it off for lab 12. By interleaving labs 9 and 11 we will be able to make solutions to
earlier stages of the lab 8-10-12 sequence available in case you don't quite finish everything.
For this lab you will be building some of the core underlying functionality of the game, but not the
Switch to the CVS Repository Exploring perspective
Check out the CSE115-Lab8 project from the Labs repository
Switch to the Java perspective
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
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.
CSE115 Lab 8
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<String>. 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<Character> 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<Character> 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
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
Define a method that takes a String as an argument a returns a HashSet<String> 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
CSE115 Lab 8
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.
Submitting your project to Web-CAT
Make sure you submit your work on time; due dates are listed at the beginning of this lab
description. This lab will be automatically graded by Web-CAT. You may submit as many times as
you wish. Your last submission is the one that counts (so consider carefully whether you want to
make any late submissions, as the late penalty is 20 points per day or portion thereof late).
Pay attention to the output produced by Web-CAT. If your submission scores 100 (without any
early submission bonus you might be entitled to) you're all set. If your submission does NOT score
100, fix the problem and resubmit. Prior to the submissions deadline we expect that you will
continue working until your submission scores 100.