Question: Programming Exercise 7.35 presents a console version of the popular hangman game. Write a GUI program that lets a user play the game. The user

Programming Exercise 7.35 presents a console version of the popular hangman game. Write a GUI program that lets a user play the game. The user guesses a word by entering one letter at a time, as shown in Figure 20.18. If the user misses seven times, a hanging man swings. Once a word is finished, the user can press the Enter key to continue to guess another word.

Write a hangman game that randomly generates a word and prompts the user to guess one letter at a time, as shown in the sample run. Each letter in the word is displayed as an asterisk. When the user makes a correct guess, the actual letter is then displayed. When the user finishes a word, display the number of misses and ask the user whether to continue to play with another word. Declare an array to store words, as follows:

// Add any words you wish in this array

String[] words = {"write",?"that", ...};

(Guess) Enter a letter in word ******* (Guess) Enter a letter in

word p****** > r JErter (Guess) Enter a letter in word pr**r**

(Guess) Enter a letter in word ******* (Guess) Enter a letter in word p****** > r JErter (Guess) Enter a letter in word pr**r** > p -Erter p is already in the word (Guess) Enter a letter in word pr**r** > o -Erter (Guess) Enter a letter in word pro*r** > g Jtrter (Guess) Enter a letter in word progr** > n PEroer n is not in the word (Guess) Enter a letter in word progr** > m JErter (Guess) Enter a letter in word progr*m > a -Erter The word is program. You missed 1 time > p JEnter Do you want to guess another word? Enter y or n> Excrcise20_07 Exercise20_07 EXerche20 or Gsa wont: * Gesa wod: * Guess a word: * |Exerchez0_07 Exercise20_07 EXenthe 20_07 Guess a wurd: reee Gessa wond: reteite Guess a ward: re"ere Missed lettes:t Mcsed letters: ty - |||x| Eercke20_07 Exercse20_07 Exerche20_07 Guess a wurd: reerre fansa wnd: reeite Guess a ward: re*ere Missed letters: tyh Missed letles: tyl Micsed letters: tyhik Exerche20_07 Exercse20_07 Dxerche20_07 Guess a word: re'eie The word is receve The word is: recelve Missed etters: tynb To continue the game, press ENTER To contnue the game, press ENTER

Step by Step Solution

3.29 Rating (164 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To generate a lottery of 3 digit number and read user guess User wins 10000 if his guess is an exact ... View full answer

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 Java Programming Questions!