Question: Question: my code keeps giving me an error that says: Exception in thread main java.lang.IllegalStateException: Active words is null! is there any way to fix
Question: my code keeps giving me an error that says: Exception in thread "main" java.lang.IllegalStateException: Active words is null! is there any way to fix this?
import java.util.Set;
import java.util.TreeMap;
import java.util.ArrayList;
import java.util.Collections;
Manages the details of EvilHangman. This class keeps
tracks of the possible words from a dictionary during
rounds of hangman, based on guesses so far.
public class HangmanManager
instance variables fields
ArrayList activeWords;
private Set dictionary;
private int numGuessesAllowed;
private ArrayList guessesMade;
private HangmanDifficulty difficulty;
private String pattern;
private int numWrongGuesses;
Create a new HangmanManager from the provided set of words and phrases.
pre: words null, words.size
@param words A set with the words for this instance of Hangman.
@param debugOn true if we should print out debugging to System.out.
public HangmanManagerSet words, boolean debugOn
if words null words.size
throw new IllegalArgumentExceptionInvalid set of words!";
dictionary words;
Create a new HangmanManager from the provided set of words and phrases.
Debugging is off.
pre: words null, words.size
@param words A set with the words for this instance of Hangman.
public HangmanManagerSet words
thiswords false;
Get the number of words in this HangmanManager of the given length.
pre: none
@param length The given length to check.
@return the number of words in the original Dictionary
with the given length
public int numWordsint length
int count ;
for String word : dictionary
if wordlength length
count;
return count;
Get for a new round of Hangman. Think of a round as a
complete game of Hangman.
@param wordLen the length of the word to pick this time.
numWordswordLen
@param numGuesses the number of wrong guesses before the
player loses the round. numGuesses
@param diff The difficulty for this round.
public void prepForRoundint wordLen, int numGuesses, HangmanDifficulty diff
Resets variables to starting values to start new round
numGuessesAllowed numGuesses;
numWrongGuesses ;
guessesMade new ArrayList;
difficulty diff;
Fills active words list with words with inputted length
activeWords new ArrayList;
fillWithGivenLengthwordLen;
pattern ;
Fills pattern with to represent unknown letters
for int i ; i wordLen; i
pattern ;
The number of words still possible live based on the guesses so far.
Guesses will eliminate possible words.
@return the number of words that are still possibilities based on the
original dictionary and the guesses so far.
public int numWordsCurrent
Systemout.printlnHERE activeWords;
ifactiveWords null
throw new IllegalStateExceptionActive words is null!";
return activeWords.size;
Get the number of wrong guesses the user has left in
this round game of Hangman.
@return the number of wrong guesses the user has left
in this round game of Hangman.
public int getGuessesLeft
return numGuessesAllowed numWrongGuesses;
Return a String that contains the letters the user has guessed
so far during this round.
The characters in the String are in alphabetical order.
The String is in the form let let let letN
For example a c e s t z
@return a String that contains the letters the user
has guessed so far during this round.
public String getGuessesMade
StringBuilder s new StringBuilder;
sappend;
If user has made any guesses
if guessesMadesize
Collections.sortguessesMade;
for int i ; i guessesMade.size; i
sappendguessesMadegeti;
Append last element
sappendguessesMadegetguessesMadesize;
Close off String
sappend;
String string stoString;
return string;
Check the status of a character.
@param guess The characater to check.
@return true if guess has been used or guessed
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
