Write a program to allow a user to play the game Hangman. DO NOT USE AN...

60.1K

Verified Solution

Question

Programming

Write a program to allow a user to play the game Hangman. DO NOTUSE AN ARRAY

The program will generate a random number (between 1 and 4581)to pick a word from the file - this is the word you then have toguess.

Note: if the random number you generate is 42, you need the 42ndword - so loop 41 times picking up the word from the file and notdoing anything with it, it is the 42nd you need. Here is how youwill do this:

String word:

for (int k=0; k<41; k++)

{word=scnr.nextLine();

}//end loop and now pick up the word you want

word=scnr.nextLine() //this is the one you want

The user will be allowed to guess a letter as many times as ittakes - but 10 wrong guesses and they lose!!

Eventually either they won or lost. In case they lost print outthe answer.

Code language: Java using JGrasp or NetBeans

Answer & Explanation Solved by verified expert
4.3 Ratings (933 Votes)
import javautilScanner import javautilRandom import javaio class defination class Hangman main function public static void mainString args variable declaration Random random new Random String word new String int wrongCount 0 game will run until user wants to exit or made 10 wrong guesses whiletrue ask user for    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students