Boggle Iteration 2: Class Boggleto WebCat
Collaboration:This is the second iteration of Boggle to be completed solo. Do not use, show, or look at any other person’s code. You may get help from your assigned TA
For this second iteration of Boggle, you are asked to complete class Boggle.
Boggle Rules: For a Boggle player to get points, the word input by the user
- must be found in the dice tray following the letter connection rules of Boggle
- must exist in our official list of words:
- must contain 3 through 16 characters (one and two letter words are not allowed)
- must not already be counted (no duplicate words allowed)
The player's score is determined by summing the points for all words found in a dictionary according to these Boggle rules (there are no negative points for incorrect guesses).
Word Length Points
3 1
4 1
5 2
63
7 5
8+ 11
Preview class Boggle with a Test: As a preview, here is one test method that shows the expected behavior of most required methods for class Boggle (most required methods shown in boldface):
@Test
publicvoidtestGetWordsFoundAfterPrepareResultsCalledWithSetBoggleTray() {
char[][] tray = {
{ 'E', 'R', 'H', 'I' },
{ 'T', 'C', 'O', 'Z' },
{ 'I', 'E', 'S', 'E' },
{ 'V', 'E', 'V', 'W' } };
BoggleTraydt = newBoggleTray(tray);
Boggle game = newBoggle();
game.setBoggleTray(dt);
game.addGuess("see");
game.addGuess("see");
game.addGuess("tEeS");
game.addGuess("Receives");
game.addGuess("Sort");
game.addGuess("cites");
game.addGuess("seCreTive");
game.addGuess("NotHere");
game.addGuess("NotHere");
game.addGuess("sew");
assertEquals(28, game.getScore());
assertEquals("[cites, receives, secretive, see, sew, sort, tees]",
game.getWordsFound().toString());
assertEquals("[nothere]", game.getWordsIncorrect().toString());
assertTrue(game.getWordsNotGuessed().contains("secret"));
assertTrue(game.getWordsNotGuessed().contains("recite"));
}
Class Boggle
The bulk of Boggle requires you to implement class Boggle using the design given below. WebCat test methods expect all of these given methods. Also, by following this design of class Boggle, it will be easy to implement the console based game and even-driven GUI in iteration 3 of this Boggle game.
The Boggle class should encapsulate all the Boggle rules and the collection of words considered to be in the list of possible words. Therefore class Boggle must have the two instance variables shown (plus others) and the seven methods shown below. Copy and paste the code below or get the class in
importjava.util.List;
publicclass Boggle {
// Boggle will use your well-tested BoggleTray.
// If you need one (did not get 100% problem coverage,
// get the working BoggleTray.java linked on the Lab page
// or directly at
privateBoggleTrayboggleTray;
// Other instance variables will be needed to store collections such
// as the 80,000+ BoggleWords ...
// Allow testers to set the BoggleTray to a known one (not random).
publicvoidsetBoggleTray(BoggleTraydt) {
this.boggleTray = dt;
}
// Return the BoggleTray object as a textual representation as a String
public String getBoggleTrayAsString() {
returnboggleTray.toString();
}
// Record one word (a string with no whitespace) as one of the users' guesses.
// Do what you want with it, but oneGuess should be processed so all methods
// can return the correct values such as getScore() and getWordsFound().
publicvoidaddGuess(String oneGuess) {
// TODO: Complete this method
}
// Return a list of all words the user entered that count for the score. The found words
// must be in their natural ordering. This method should return an empty list until
// addGuess(String) is called at least once. The returned List<E> could also be empty if
// no attempts actually counted for anything. There must be no duplicates!
public List<String> getWordsFound() {
// TODO: Complete this method
returnnull;
}
// Return a list of all words the user entered that do not count for the score
// in their natural order. This list may be empty with no words guessed or all
// guessed words actually count for points. There must be no duplicates!
public List<String> getWordsIncorrect() {
// TODO: Complete this method
returnnull;
}
// All words the user could have guessed but didn't in their natural order.
// This list could also be empty at first or if the user guessed ALL words
// in the board and in the list of 80K words (unlikely).
// There must be no duplicates!
public List<String> getWordsNotGuessed() {
// TODO: Complete this method
returnnull;
}
// Return the correct score.
publicintgetScore() {
// TODO: Complete this method
return -1;
}
}
Use Java's Collection Framework
The Boggle class will need some collection instance variables--your choice. You will also be using several java.util.List<E> objects as return types. Use either java.util.ArrayList<E> or java.util.LinkedList<E> that both implement the java.util.List<E> interface. Here are some important methods from the List interface that both ArrayList and LinkedList have at the ready:
// Add an element at the end if the List
public booleanadd(E element)
// Determine if a List contains a particular element using E's equals method
public booleancontains(E element)
// Return a reference to the element at the given index
E get(int index)
// Return the number of elements in this list
public intsize()
A few generic algorithms you might find useful
// Randomly shuffle the array elements
Collections.shuffle(List<E>)
// Arrange all elements in the List<E> argument into their natural ordering
Collections.sort(List<E>)
// Return the index of the found element or a negative integer if not found
Collections.binarySearch(List<E>, E element)
String methods you should use to ensure the user can enter upper and/or lower case letters and there are no leading or trailing blanks.
// Return a new String that has all lower case letters changed to upper case.
public String toUpperCase()
// Return a new String that has all upper letters changed to lower case.
public String toLowerCase()
// Return a new String that has all leading and trailing spaces removed
public String trim()
Turn this into WebCat 40 points
The 2ndpart of Boggle should have these files:
- BoggleTray.java
- BoggleTrayTest.java
- Boggle.java
- BoggleTest.java
- BoggleWords (Do not place in in src, put input files in the Eclipse project).
Grading CriteriaClass Boggle80 points via WebCatTurnin
+60 WebCat Problem Coverage
1