Learning ObjectivesBe able to create a program without a template.Be able to discern the requirements from a problem.Be able to understand how to translate from "word" to "code".AssignmentHangman...

1 answer below »



Learning Objectives







  • Be able to create a program without a template.



  • Be able to discern the requirements from a problem.



  • Be able to understand how to translate from "word" to "code".










Assignment




Hangman is a word-guessing game that can be played by two people. Player 1 thinks of a single word consisting of N letters, and draws a row of N dashes on a piece of paper. These dashes correspond to the letters of the word, in the same order. Player 2 then attempts to discover the word by making a sequence of letter guesses. For each letter guessed by Player 2:










  • If the letter occurs one or more times in the word, Player 1 writes the letter above each corresponding dash.










  • If the letter does not occur in the word, Player 1 adds one component to a drawing of a stick-figure man hanging on a gallows. The drawing (initially empty) has 10 possible components: base, vertical beam, horizontal beam, rope, head, torso, right leg, left leg, right arm, left arm.










If Player 2 guesses all the letters in the word before the drawing of the hanging man is complete, then Player 2 wins (and Player 1 loses). Otherwise, Player 2 loses (and Player 1 wins).




When the game starts, Player 1 will input a word. Then, Player 2 will guess the word. Since we don't want Player 2 to see the word input by Player 1, you will "clear" the screen by outputting 25 blank lines AFTER Player 1 enters a word. Now, you will ask Player 2 for a letter until either Player 2 guesses all of the correct letters or Player 2 guesses 10 incorrect letters.




NOTE: Capitalization will NOT be enforced for words (e.g. your program must match h with H or vice-versa).




At the end of the game, print out who won the game--either Player 1 or Player 2. Then, ask if the user wants to play the game again.




Hints and Restrictions







  • Do NOT repeat code. If you can use a method, call the method and do not re-write the same code!



  • You probably should create a class with methods to perform the basic actions: print out the number of limbs left, print out the word with dashes, determine if a letter was already guessed (or not), and a way to reset if the user wants to play another game.



  • You can use the String class or StringBuilder to determine the size of the word Player 1 enters.



  • You can use an ArrayList to store the guessed letters to ensure Player 2 doesn't guess the same letter more than once.



  • You can look at individual characters in a String by using the charAt(index) method, and you can see how many characters are in a string by using the length() method.



  • You can lower every letter in a String by using the toLowerCase() method. This returns a new String.



Answered Same DayDec 07, 2022

Answer To: Learning ObjectivesBe able to create a program without a template.Be able to discern the...

Vikas answered on Dec 07 2022
31 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here