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

PLEASE READ INSTRUCTIONS FIRST! DO NOT COPY AND PASTE YOUR CODE. TAKE A SCREENSH

ID: 3544267 • Letter: P

Question

PLEASE READ INSTRUCTIONS FIRST! DO NOT COPY AND PASTE YOUR CODE. TAKE A SCREENSHOT OF THE CODE AND SHOW THAT IT WORKS. DO NOT COPY AND PASTE THE CODE AS A TEXT.




Write an interactive program that plays a game of hangman. Store the word to be guessed in in successive elements of an array of individual characters called word. The player must guess the letters belonging to word. The program should terminate when either all letters have been guessed correctly (the player wins) or a specified number of incorrect guesses have been made (the computer wins). Use another array named guessed to keep track of the solution so far. Initialize all elements of guessed to the character. Each time a letter in word is guessed, replace the corresponding in guessed with that letter. Hint: You can just use a word of your choosing for the word to be guessed. Use at least two functions to implement the game.

Explanation / Answer

void main()
{
int words,n,i,choice;
Random gen = new Random();
int maxTries = 8;
int wordLength,index,foundletters;
boolean solved,found;
Scanner inScan = new Scanner(System.in);
char letter;
String secretWord="";
System.out.println("Welcome to Hangman!");
StringBuffer guessedLetters = new StringBuffer();
Scanner fileScan = new Scanner(new FileInputStream("words.txt"));
words=fileScan.nextInt();
n=gen.nextInt(words);
for(i=0;i<=n;i++)
secretWord = fileScan.next().toLowerCase();
fileScan.close();
foundletters=secretWord.length();
//Creates a StringBuffer for the viewing of the letters guessed
StringBuffer word = new StringBuffer();
for(i = 0; i < secretWord.length(); i++)
word.append("_ ");

System.out.print("The word now looks like this: ");
System.out.println(word);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote