Question

Write a game of hangman using arrays. Allow the user to guess letters until the guess a word correctly within the parameters of the game. Also use an array to represent which letters have been guessed already to keep track.

Things to keep in mind:

1. Create a file containing at least 10 words. These will represent the words used in the game. You can expand the game to include more than 10 words if you wish. When the program starts, store these words into an array of strings.

2. When the game starts, the program should randomly choose a word from the array of strings as described in #1.

3. The player tries to guess the letters that are in the word. The game continues until the user either guesses the whole word/ letters, or they run out of turns. Each time the user guesses an incorrect letter, part of the gallows should be displayed.   There should be eight body parts to the person: head, torso, leftArm, rightArm, LeftLeg, rightLeg, leftFoot and Rightfoot. You should use characters to represent the figure.

4. The game ends by either the users guessing the characters in the word without making any more than 7 mistakes. Or if the user makes 8 incorrect guesses.


Sample Run:

Hangman Game!

You have guessed the following letters:
_ _ _ _ _

Enter a letter:                                                          //let’s say the users types ‘u’

You have guessed the following letters: u
_ _ u _ _

Enter a letter:                                                         //let’s say the user types ‘s’                                                

S! not found. 7 more guesses remain.
_____
O       |                //the head is drawn
          |
          |
          |
    ______
You have guessed the following letters: u , s
_ _ u _ _

Enter a letter:                   //the user enters ‘h’            
You have guessed the following letters: u , s , h
h _ u _ _

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.io.; for File
import java.util.; for Scanner
import java.util.Random; for Random number

public class Hangman
{
public static void main(String[] args) throws FileNotFoundException { Read words from a file words.txt
Scanner input = new Scanner(new File(words.txt));
String[] words = new String[10];
int i = 0;
while (input.hasNext()) {
words[i] = input.next();
i++;
}
Random randomInteger = new Random();
String mAnswer = words[randomInteger.nextInt(10)];
String mHits = ;
String mGuessed = ;
String mMisses = ;
System.out.println((The answer is + mAnswer+));


System.out.println(nHangman Game!);
displayProgress(mAnswer, mHits,mGuessed);
while ( getRemainingTries(mMisses)0 && !isSolved(mAnswer, mHits) ) {...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

Railroads Problem
Homework Solution
$100.00
Java Programming
Computer Science
Graph
Input
Arrival
Output
Railroad
Scenario
Location
Java Program: Arrays Of Marks
Homework Solution
$30.00
Java
Programming
Codes
Computer Science
Algorithms
Arrays
Marks
Characters
Strings
Integers
Maximum Value
Minimum Value
Difference
Range
Median
Sorting Methods
Boundaries
Statements
Vaariables
Java Program for Volleyball Scores
Homework Solution
$20.00
Java
Programming
Computer Science
Volleyball
Scores
Points
Users
Loops
Arrays
Statements
Variables
Teams
Matches
Data Sets
Input
Output
Java Programming: Integer Problems
Homework Solution
$20.00
Programming
Java
Computer Science
Integers
Variables
Average Values
Even Numbers
Odd Numbers
Loops
Statements
Input
Output
File Management
Conditions
Error Messages
Exceptions
Cylinder Containers in Java
Homework Solution
$25.00
Java
Programming
Codes
Algorithms
Computer Science
Statements
Variables
Loops
Input
Output
Integers
Strings
Geometry
Mathematics
Cylinder
Radius
Finance
Costs
Containers
Companies
Functions
Get help from a qualified tutor
Live Chats