Question: JAVA public static void startGame(String[] words, int minLength, int maxLength, String allowedChars) This method is guaranteed to be called exactly once by SnowmanRunner at the

JAVA

public static void startGame(String[] words, int minLength, int maxLength, String allowedChars)

This method is guaranteed to be called exactly once by SnowmanRunner at the beginning of the program execution, and after that, never again. Inside this method, you can do whatever initialization computations you wish to perform to optimize your success in the game, such as counting the individual letter frequencies in words. The parameters are as follows:

words is an array of Strings that contains all possible words of English that the secret words are randomly chosen from.

minLength and maxLength are the minimum and maximum lengths of the secret words, respectively. Your code can safely assume that the secret word length is between these two, inclusive.

allowedChars is a String that contains all possible characters that can occur in the secret words. (This would be the 26 lowercase letters of the English alphabet.)

public static void startNewWord(int length)

The method startNewWord(int) is called by SnowmanRunner at the start of each new round (which will have a new secret word). Inside this method, you can perform whatever initialization you need for guessing each individual secret word. The parameter length tells you the length of the secret word (so that you can ignore all the potential secret words that have a different length).

public static char guessLetter(String pattern, String previousGuesses)

The method guessLetter(String, String) is called by SnowmanRunner to ask your code what letter it would like to guess next for the current secret word. Your method answers by returning a char. The parameters of guessLetter() are as follows:

pattern is a String that contains the current secret word so that each unknown letter is displayed as the character SnowmanRunner.BLANK (currently the asterisk character), and each known letter is displayed as that letter. For example, if the secret word is seven characters long, and you have previously made the successful guesses 'n' and 's', the pattern might be "sn****n".

The game of Snowman

In this assignment, you implement a player for a familiar childrens game in which your program tries to guess a secret word one letter at a time. For example, if the secret word is snowman, then the player begins with the letters hidden: *******. Each guess that does not appear in the word is a miss and scores one point. Each guessed letter which does appear in the word replaces the corresponding asterisks with the correct letter. For example, a guesss of n, results in *n****n. The fewer misses your program does overall, the better. The guessing ends when all of the letters have been guessed, to reveal the hidden word, in this case snowman. previousGuesses is a String that contains the characters that you have already guessed for this particular secret word, including both hits and misses. (Of course, it would be rather silly for your method to return as your guess some character from previousGuesses, or some character that is not in allowedChars.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!