java hangman program
Java Programming I Final PortfolioComplete the Java Programming I Final portfolio. When you are finished,submityourassessment to your instructor by using the Drop Box on page 13.Portfolio OverviewBy completing this activity, you will gain experience with nearly every programming subject covered in the course.Portfolio GoalA document containing a copy of your program source code text with commented output added demonstrating winning and losing games.Portfolio DetailsFor this final portfolio, you will be creating a game of Hangman. The program will randomly generate a word and display a set of spaces showing the missing characters.Welcome to Hangman.Here is your word: --------Your guess:The player will guess characters one at a time. The game will report a message and update the players progress based on the results of each guess.Your guess: aa not found!You have used 1 out of 5 missed guesses.Progress: ------Your guess: eCorrect!Progress: -e----The game ends when the player runs out of missed guesses or uncovers all the letters in the word.Your guess: pCorrect!You found all the letters in the word "report".You win!Your guess: bSorry, you lose.The word was "antelope".This project involves several programming concepts you encountered throughout the course including object oriented programming. An object will keep track of most of the games information and provide methods that grant access to that data.The instructions for this project are fairly detailed, but it is up to you to understand the instructions and implement the proper solutions.InstructionsThere will be two classes in this project:HangmanandHangmanWord.Hangmanwill have a main method. It will provide the output and control when the game ends.HangmanWordwill be used to create an object that will keep track of the games word, the letters the user has guessed correctly, the number of incorrect guesses the user has made, and whether the word has been solved or not.TheHangmanWordClassCreate a public class named HangmanWord. Inside this class, do the following:Create a private instance array ofStringreferences namedpossibleWords. Assign topossibleWordsa populated array of strings of your choosing. This will be the list of words the program will randomly select from. Include at least three strings with at least five letters each.Create a private instance variable of typeStringnamedword. This variable will remember the word from thepossibleWordsarray that will be randomly selected later.Create a private instance array ofcharnamedprogress. After the games word is randomly selected, an array ofcharwill be created with a number of elements equal to the length of the word. It will originally be filled with dash characters, but later, correctly guessed letters will replace the dashes.Create a private instanceintvariable namedwrongCountand set it to zero. This will keep track of the number of incorrect guesses the user makes.Create a public constructor that has no parameters. Inside this constructor, do the following:Generate a random number from zero to the length of thepossibleWordsarray minus one. For example, if you have five words in thepossibleWordsarray, you should generate a random number from0to4, inclusive. This will be the index of the randomly selected word.Assign, to the instance variableword, theStringfound inpossibleWordsat the index you just generated.Create and assign, to instance variableprogress, a new array ofcharwith a number of elements equal to the length of theStringyou just assigned toword.Use the appropriate method from theArraysclass to fill all the elements of progress with the dash character ('').Review, for your own understanding, everything that will happen when aHangmanWordobject is created using this constructor.Create an instance method nameddisplaythat has no parameters and returns nothing. Inside display, do the following:Loop through all of the characters inside ofprogressand display them all on one line usingSystem.out.print().After the loop is finished, add one blankSystem.out.println()statement.Create a method namedguess()that will accept onecharnamedcas an argument and returns aboolean. Insideguess(), do the following:Declare abooleanvariable namedmatchFoundand set it to false. This variable will remain false untilcmatches one of the characters in word.Create aforloop with index variableithat starts at zero and ends less than the length ofword. For example, ifwordis"cat", yourivariable would loop from0to2. This will loop through the indices of all of the characters inword. Inside this loop:Comparewords character at index i to the incoming characterc. If they match:* Update theprogresschar array by setting the element at indexito the value ofc.* Set the value ofmatchFoundtotrue;See the next slide for more details on this step.Let's examine what's going on here.Suppose that"supreme"and the incoming value ofcis'e'.In the constructor, you made achararray namedprogresswith a size equal to the length ofwordand filled it with dashes. In this case, it would look like this:-------The word"supreme"has letters starting at index 0 and ending at index 6. Yourforloop would loop from 0 to 6.The first time through the loop, indexiis0.word.charAt(i)is's'.'s'is not equal tocsvalue of'e', so do nothing.The next time through the loop, indexiis1.word.charAt(i)is'u'.'u'is not equal tocs value of'e', so do nothing.Whenireaches4,word.charAt(i)is'e'.'e'is equal toc's value of'e'. Since this istrue, setprogress[i]to the value ofc. If we displayed it,progresswould look like this:----e--Whenireaches6,word.charAt(i)is'e'.'e'is equal tocs value of'e'. Since this istrue, setprogress[i]to the value ofc. If we displayed it,progresswould look like this:----e-eAt the end of theguess()method, return the value ofmatchFound.Create an instance method namedisSolved()that has no parameters and returns aboolean. This method will reporttrueif all of the characters in the word have been guessed. InsideisSolved(), do the following:Loop through all of the characters in theprogressarray. If any of them are equal to a dash character, immediately returnfalsefrom the method.After the loop, returntrue. If the loop did not find any dash characters, then all of the letters must have been guessed and the word has been solved, so returntrue.Create an instance method namedgetWrongCount()that has no parameters and returns anint. Have this method return the value ofwrongCount.Create an instance method namedgetWord()that has no parameters and returns aString. Have this method return the value ofword.TheHangmanClassCreate a class namedHangmanin the same package asHangmanWord. InsideHangmanWord, create amainmethod, and inmain, do the following:Declare a constantintvalue namedMAX_INCORRECTand assign it a value of5. If the user guesses wrong this many times, the game will be over.Display the welcome message,Welcome to Hangman.Create aHangmanWordobject and assign the reference to this object to a reference variable namedwordObj.UseSystem.out.print()to display the message,Here is your word: Call thedisplay()method onwordObj.Compile and run your program. If everything is working, you should see output that looks like this:Welcome to Hangman.Here is your word: ------The number of dashes will vary depending on which wordwordObjrandomly chose.Create aScannerobject to read input from the keyboard.Create awhileloop that will loop indefinitely. Inside this loop, do the following:UseSystem.out.printto display a newline character andYour guess: Since there is nonextChar()method inScanner, instead usenextLine()to read aStringfrom yourScannerand assign the value to a variable namedguess.Assign the first character of guess to acharnamedguessChar.PassguessCharto theguess()method ofwordObj. Use the result of this method call in anif-elsestatement.Process a correct guess.If the result ofwordObj.guess(guessChar)istrue, do the following:Display"Correct!"Has the game been won?Call theisSolved()method onworkdObj. IfwordObj.isSolved()istrue, do the following:Display the following messages:You found all the letters in the word "xxxx".You win!Replacexxxxwith the word stored inwordObj, which you can retrieve by callinggetWord(). Surround the word with quotation marks in the output.Use thebreakkeyword to break out of the loop and end the program.The game hasn't been won yet.Else, do the following:UseSystem.out.print()to display"Progress:"CallwordObj.display().The above two steps should display something like the following:Progress: a--e---eYour output will vary based on the word being used and the guesses so far.Process an incorrect guess.Else (if the result ofwordObj.guess(guessChar)isfalse), do the following:CallwordObj.getWrongCount()and use the result in anif-elsestatement.Has the game been lost?IfwordObj.getWrongCount()is greater than or equal toMAX_INCORRECT, display the following:Sorry, you lose.The word was "xxxx".Replacexxxxwith the word stored inwordObj, which you can retrieve by callinggetWord(). Surround the word with quotation marks in the output.The game has not been lost yet.Else, display the following:? not found!You have usedxout ofymissing guesses.Progress: a--e-o-eReplace?with the character the player just guessed. Replacexwith the result ofwordObj.getWrongCount()andywith the value ofMAX_INCORRECT.TestingRun your program two or three times to confirm that it is working correctly. Compare your output to the samples below. Troubleshoot and fix any bugs in logic or output that you find.Sample output 1:Welcome to Hangman.Here is your word: ------Your guess: aa not found!You have used 1 out of 5 missed guesses.Progress: ------Your guess: eCorrect!Progress: -e----Your guess: ii not found!You have used 2 out of 5 missed guesses.Progress: -e----Sample output 1, continued:Your guess: oCorrect!Progress: -e-o--Your guess: uu not found!You have used 3 out of 5 missed guesses.Progress: -e-o--Your guess: rCorrect!Progress: re-or-Your guess: tCorrect!Progress: re-ortYour guess: pCorrect!You found all the letters in the word "report".You winSample output 2:Welcome to Hangman.Here is your word: --------Your guess: aCorrect!Progress: a-------Your guess: eCorrect!Progress: a--e---eYour guess: ii not found!You have used 1 out of 5 missed guesses.Progress: a--e---eYour guess: oCorrect!Progress: a--e-o-eSample output 2, continued:Your guess: uu not found!You have used 2 out of 5 missed guesses.Progress: a--e-o-eYour guess: rr not found!You have used 3 out of 5 missed guesses.Progress: a--e-o-eYour guess: ss not found!You have used 4 out of 5 missed guesses.Progress: a--e-o-eYour guess: tCorrect!Progress: a-te-o-eSample output 2, continued:Your guess: nCorrect!Progress: ante-o-eYour guess: bSorry, you lose.The word was "antelope".copy and paste the following iteams into a documentthe code from the hangman classThe code form the hangman world classoutput from winging gameoutput from losing game
THIS QUESTION IS UNSOLVED!
Request a custom answer for this question