1. Engineering
  2. Computer Science
  3. overview in this exercise you are going to recreate the...

Question: overview in this exercise you are going to recreate the...

Question details


In this exercise you are going to recreate the classic game of hangman. Your program will randomly pick from a pool of words for the user who will guess letters in order to figure out the word. The user will have a limited number of wrong guesses to complete the puzzle or lose the round. Though if the user answers before running out of wrong answers, they win.



The program will use 10 to 15 words as its pool for users to guess from. You may pick your own words. The words must be between 5 to 10 characters each. In a traditional hangman game, the person guessing can make 8 incorrect guesses. Each correct guess of a letter does not count against the number of incorrect guesses. When the player reaches 8 incorrect guesses, the game is over.

When the user starts the program, one of the words from the list will be chosen at random for the user to guess. Before the user starts, the program will show the word as a series of asterisks (*) where each letter is replaced with an asterisk (*). For example, if the word is dragon, the user will be given the message, "Please guess the following word * * * * * * . You have 7 wrong guesses left".

As the game progresses, the user will guess letters one at a time. Each time the user guesses a letter, the program will either reveal the letters in the word that match, give a warning that they guessed a letter they already had guessed or that the letter does not exist in the word. After a guess, the program will output the message, with all of the currently solved letters and the rest of the unknown letters still replaced by * and then a count of how many wrong guesses left.

Each time the user either chooses a letter that is wrong or that they have already chosen, the program will deduct a guess from the number of tries they have left. After they have exhausted all of their guesses, the program will output a message that they have lost and offer to let them play again. If they solve the word, then the program will display a congratulatory message and ask them if they wish to play again.

Each subsequent play-through will not allow a previously used word to be chosen so be sure to keep track of these words through some method. If there are no more words to choose then the program needs to end with a message saying in some manner that it is out of words, thanks for playing and have a nice day.

Java Requirements

The program must utilize a number of single dimensional arrays to track the state of the program. At a minimum, you will need one array of characters to track the current word, you will need one array of words to track which words have been chosen or are left to be chosen. How you define the logic and utilize these arrays is up to you.

The program must be created from an object oriented perspective. You will likely want a function for running the game, one for picking the words, another for judging if a letter is in the word, etc. If you load up your main() with all or most of the functionality, you will be penalized harshly. Hint: If the program has to "perform a task", that task can likely be made into a function or method.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution