Hangman is a game that can be played between two players. One player thinks of a word and the other tries to guess it by suggesting letters. The word to guess is represented by a row of '?', giving the number of letters in the word. If the guessing player suggests a letter which occurs in the word, the other player writes it in all its correct positions. See http://en.wikipedia.org/wiki/Hangman_(game) for further details).
The hangman class will have at least the following attributes:
The secret word or phrase (a String, which may include embedded white spaces and punctuation characters)
The disguised word, in which each unknown alphabetic letter in the secret word is replaced with a question mark (?). When an unknown letter is guessed correctly, it will replace the corresponding question mark(s) in the disguised word. For example, if the secret word is abracadabra and the letters a and b have been guessed, the disguised word would be ab?a?a?ab?a.
The number of guesses made.
The number of incorrect guesses. The hangman class will have at least the following methods:
makeGuess(ch) guesses that character ch is in the word.
getDisguisedWord returns a String containing correctly guessed letters in their correct positions and unknown letters replaced with ?.
getSecretWord returns the secret word.
getGuessCount returns the number of guesses made.
isFound returns true if the hidden word has been discovered. Devise any additional methods and attributes that are needed in the class and are not listed above. Note that when treating letters of the alphabet, case is not important (i.e., the uppercase and lowercase forms of the same letter are to be treated the same). Write a client class that tests the hangman class. The client class should allow the user to play three games of hangman. The client class will have the three secret words (or phrases) built into it as String variables. Note that the client class only needs to have the main method which creates an object of the hangman class, sets the secret word and passes control to the hangman class. Do not use arrays in this program. The test results from the program should be submitted as part of your external documentation. Your program should also include a method (eg, StudentInfo( )) to output your student details (name, student number, mode of enrolment, tutor name, tutorial attendance day and time) at the start of program output.
Here is some sample output (the user input is in bold):
Let’s play a round of hangman. We are playing hangman The disguised word is Guess a letter: a Correct. Guesses made 1 with 0 wrong The disguised word is Guess a letter: 7 Sorry, your guess must be an alphabet character from a to z Guesses made 1 with 0 wrong The disguised word is Guess a letter: p Incorrect. Guesses made 2 with 1 wrong The disguised word is Guess a letter: ha Sorry, bad guess. Need a single letter. Guesses made 2 with 1 wrong The disguised word is Guess a letter: h Correct. Guesses made 3 with 1 wrong The disguised word is Guess a letter: r Incorrect. Guesses made 4 with 2 wrong The disguised word is Guess a letter: l Correct. Guesses made 5 with 2 wrong The disguised word is Guess a letter: s Incorrect. Guesses made 6 with 3 wrong The disguised word is Guess a letter: n Correct. Guesses made 7 with 3 wrong The disguised word is Guess a letter: 0 Sorry, your guess must be an alphabet character from a to z Guesses made 7 with 3 wrong The disguised word is Guess a letter: o Correct. Guesses made 8 with 3 wrong The disguised word is Guess a letter: b Incorrect. Guesses made 9 with 4 wrong The disguised word is Guess a letter: c Correct. Guesses made 10 with 4 wrong The disguised word is Guess a letter: y Correct. Guesses made 11 with 4 wrong Congratulations, you found the secret word: halcyon *************************************************** Let’s play a second round of hangman. We are playing hangman The disguised word is Guess a letter: b Correct. Guesses made 1 with 0 wrong The disguised word is Guess a letter: 9 Sorry, your guess must be an alphabet character from a to z Guesses made 1 with 0 wrong The disguised word is Guess a letter: ... ...
The above example did not show how the user can exit the program. Think of a way that you can allow user to exit the program (not using Ctrl+C)
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference
and should not be submitted as is. We are not held liable for any misuse of the solutions.
Please see the frequently asked questions page
for further questions and inquiries.
Kindly complete the form.
Please provide a valid email address and we will get back to you within 24 hours.
Payment is through PayPal, Buy me a Coffee
or Cryptocurrency.
We are a nonprofit organization however we need funds to keep this organization operating
and to be able to complete our research and development projects.