Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

package Hangman; import java.util.*; public class DictionaryManager { final stat

ID: 3547586 • Letter: P

Question

package Hangman;


import java.util.*;


public class DictionaryManager {


final static String[] dictionaryArray = {"scissor",

"size",

"98 more words and phrases"};


public static void main(String[] args) {


}


public static String[] initDictionary () {

// Returns a randomly sorted list of words that

// will be used as the dictionary for the current game.

String[] gameDictionary = Arrays.copyOf(dictionaryArray, dictionaryArray.length);


return gameDictionary;

}


public static String pickSecretWord (String[] dictionary) {

// Picks the next secret word or phrase from the dictionary. To do this,

// search through the dictionary array until an empty string is found.

// The next secret word will be the last array element before the empty string.

// If all the words have been used in the game (array element 0 is the empty string),

// initialize the dictionary again.

// Put an empty string in the element that was used for the secret word, otherwise words

// will be reused in the same game.

// Returns the secret word.

String secretWord = "";


return secretWord;

}


public static boolean isLetterInSecretWord (String secretWord, char letter) {

// if letter is contained in secretWord, return true otherwise return false.

boolean result = false;


return result;

}


public static int nextPosition (String secretWord, char letter, int previousPosition) {

// Finds a letter in secretWord, starting the search from the previousPosition.

// Returns the position of the letter or a -1 if the letter was not found.

// This method is useful if the same letter appears more than once in secretWord.

int nextPos = -1;


return nextPos;

}

}

Explanation / Answer

import java.util.*; public class Hangman { ////////////////////////////////////////////////////////////////////// // 1. CLASS VARIABLE ////////////////////////////////////////////////////////////////////// private static String [] words = //choose secret word from these {"geography", "cat", "yesterday", "java", "truck", "opportunity", "fish", "token", "transportation", "bottom", "apple", "cake", "remote", "pocket", "terminology", "arm", "cranberry", "tool", "caterpillar", "spoon", "watermelon", "laptop", "toe", "toad", "fundamental", "capitol", "garbage", "anticipate", "apple"}; ////////////////////////////////////////////////////////////////////// // 2. INSTANCE VARIABLES ////////////////////////////////////////////////////////////////////// private String secretWord; // the chosen secret word private ArrayList correctLetters; // correct guesses private ArrayList incorrectLetters; // incorrect guesses private Scanner stdin = new Scanner(System.in); // for user input ////////////////////////////////////////////////////////////////////// // 3. CONSTRUCTOR ////////////////////////////////////////////////////////////////////// /** * Constructs a Hangman game. */ public Hangman() { //REMOVE LINE BELOW WHEN DONE TESTING this.secretWord = "miscellaneous"; //Randomly choose a word from list of words //UNCOMMENT LINES BELOW TO PLAY WHEN DONE TESTING //Random randIndex = new Random(); //int index = randIndex.nextInt(Hangman.words.length); //this.secretWord = Hangman.words[index]; this.correctLetters = new ArrayList(); for (int i = 0; i = 4) { System.out.println(" | \|/"); } } if (badGuesses > 4) { poleLines = 3; if (badGuesses == 5) { System.out.println(" | /"); } else if (badGuesses >= 6) { System.out.println(" | / \"); } } if (badGuesses == 7) { poleLines = 1; } for (int k = 0; k