Write a program called Word Guessing Game. write the contents from the list belo
ID: 3547811 • Letter: W
Question
Write a program called Word Guessing Game. write the contents from the list below into an array of Strings
(the file has 87 words in it). Then use a randomly generated number between 0 and 86 to select a word.
The player will then try to guess the word
selected by the game. The player is allowed 7 tries, if the player does not guess the word on the 7th try he/she losses. Display the
letter of the word as they are guessed in the correct order, you will also display the incorrect letters.
The game is over
when:
Explanation / Answer
import java.io.*; import java.util.Scanner; public class finalProject { public static void main(String args[]) throws FileNotFoundException { /* counter for guesses? maybe? */ } public static void showAvailableLetters() { /* should contain an array of the alphabet * when a letter is guessed, replace that letter with * * output the array */ String[] letters = new {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; public static inputGuess { /* ask for input, use a try catch to see if it's valid, then check * to make sure: it's one letter, it's a letter, not a number/null. * if the letter has already been guessed, ask for another input and don't increase the guess counter * send info to showAvailableLetters method (replace letter with *) * check to see if the letter is in the word (while loop for # of guesses) */ System.out.println("Enter your guess: "); try{ guess=console.next(); } catch(Exception e){ System.out.println("You have entered an invalid letter!"); } } public static checkForLetter(guess) { /* send in the letter * indexOf to see if the letter's there * if the letter is in the word, replace the letter with *, print word return yes * if it's not, print the regular word, return no */ } public static wordGuessed { /* if there are any letters left, return false and keep loop going, if not they won. */ } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.