Answered step by step
Verified Expert Solution
Question
1 Approved Answer
solve a somewhat larger problem whose solution incorporates the programming concepts that you have been studying: Variables, Data Types, Control Structures (if-then, if-then-else, loops, switch,
solve a somewhat larger problem whose solution incorporates the programming concepts that you have been studying: Variables, Data Types, Control Structures (if-then, if-then-else, loops, switch, etc.), Method Definitions, and Arrays.
Your problem is to create a Java program to implement the game "Hang Man."
Hang Man is a relatively simple game that requires the user to guess the letters of a word before running out of incorrect guesses. Each incorrect guess will "build" another part of the Man who is hanging from the gallows. When the game starts, the user is presented with an "unoccupied" gallows, all the letters in the alphabet, and a set of blanks representing the letters in the word:
----------------
| | 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
|
|
|
|
_ _ _ _ _ _ _ _ _ _
This word has 10 letters.
The user guesses a letter, let's say 'a'. The program determines if there is an 'a' in the word and
"uncovers" all the 'a' letters in the word. In addition to finding the a's in the word, it also removes 'a'
from the alphabet so the user knows that a should not be chosen again.
----------------
| | _ 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
|
|
|
|
_ a _ a _ _ _ _ _ _
The user guesses the next letter, let's say 'n'.
----------
| | _ b c d e f g h i j k l m _ o p q r s t u v w x y z
| O
|
|
|
|
_ a _ a _ _ _ _ _ _
There are no n's in the word so the head of the man appears on the gallows. Notice that 'n' is also
removed from the list of available letters.
If the user continues to guess incorrectly, the man will continue to be "built" until the total man appears
on the gallows and the user loses the game.
----------
| | _ b c d e f _ h i j k _ m _ o p _ r s t _ v w _ _ z
| O
| / |
| |
| /
|
_ a _ a _ _ _ _ _ _
The correct word is displayed: javascript
Program Requirements:
There are plenty of Java programs that you can find that play the game Hang Man. To discourage you
from using that code I am requiring the following program elements.
The correct word is javascript
1. Your program must have an array of words (Strings) from which one of the words is randomly chosen
to play a round of the game. Please don't include more that 5 words so that I can easily test your
program: String [ ] words = { "javascript", "declaration", "object", "class", "failing" };
2. Your program must contain at least one character array such as: char [ ] alphabet;
3. Your program must contain at least 3 method definitions not including the main method definition.
4. One of the method definitions must be a method called: explode
The explode method is sent a string such as: "javascript" and returns an array of characters
containing the letters that appear in the words: 'j' 'a' 'v' 'a' 's' 'c' 'r' 'I' 'p' 't'
When the user is asked to make a letter guess, you can assume that the user will type a valid character
Your problem is to create a Java program to implement the game "Hang Man."
Hang Man is a relatively simple game that requires the user to guess the letters of a word before running out of incorrect guesses. Each incorrect guess will "build" another part of the Man who is hanging from the gallows. When the game starts, the user is presented with an "unoccupied" gallows, all the letters in the alphabet, and a set of blanks representing the letters in the word:
----------------
| | 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
|
|
|
|
_ _ _ _ _ _ _ _ _ _
This word has 10 letters.
The user guesses a letter, let's say 'a'. The program determines if there is an 'a' in the word and
"uncovers" all the 'a' letters in the word. In addition to finding the a's in the word, it also removes 'a'
from the alphabet so the user knows that a should not be chosen again.
----------------
| | _ 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
|
|
|
|
_ a _ a _ _ _ _ _ _
The user guesses the next letter, let's say 'n'.
----------
| | _ b c d e f g h i j k l m _ o p q r s t u v w x y z
| O
|
|
|
|
_ a _ a _ _ _ _ _ _
There are no n's in the word so the head of the man appears on the gallows. Notice that 'n' is also
removed from the list of available letters.
If the user continues to guess incorrectly, the man will continue to be "built" until the total man appears
on the gallows and the user loses the game.
----------
| | _ b c d e f _ h i j k _ m _ o p _ r s t _ v w _ _ z
| O
| / |
| |
| /
|
_ a _ a _ _ _ _ _ _
The correct word is displayed: javascript
Program Requirements:
There are plenty of Java programs that you can find that play the game Hang Man. To discourage you
from using that code I am requiring the following program elements.
The correct word is javascript
1. Your program must have an array of words (Strings) from which one of the words is randomly chosen
to play a round of the game. Please don't include more that 5 words so that I can easily test your
program: String [ ] words = { "javascript", "declaration", "object", "class", "failing" };
2. Your program must contain at least one character array such as: char [ ] alphabet;
3. Your program must contain at least 3 method definitions not including the main method definition.
4. One of the method definitions must be a method called: explode
The explode method is sent a string such as: "javascript" and returns an array of characters
containing the letters that appear in the words: 'j' 'a' 'v' 'a' 's' 'c' 'r' 'I' 'p' 't'
When the user is asked to make a letter guess, you can assume that the user will type a valid character
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Creating a Hangman game in Java involves several components including word selection game logic user input and graphical representation ASCII art Belo...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started