Answered step by step
Verified Expert Solution
Question
1 Approved Answer
without string buffer and io exception Enhance the Number Guessing Game program from the exercises, changing it to a Guess the Letter game. 1. Ask
without string buffer and io exception
Enhance the Number Guessing Game program from the exercises, changing it to a Guess the Letter" game. 1. Ask the user for a phrase, at least 5 characters in length; example: "Dogs always wag their tails" and remove the spaces in the string (use the String method .replaceAll(" "."")) With the length L of the string, calculate a random character position P, and the number of chances C to guess the number (C-L+5); example: string length L-23, P is random valuefrom 1.23, C-23-5-28 2. 3. Loop while the user has not guessed the correct character and number of chances C has not run out a. For each time the user guesses, i. If the guess is correct, the program displays, "Congrats! You guessed correctly in N guesses" where N is the number of guesses (loops) that have occurred; and the loop stops - ii. If the guess is incorrect, the program displays, Try again. You have only R guesses remaining" where R the number of remaining guesses (R C-number of guess (loops) so far) 4. If the user is unable to guess within the C number of chances, the program displays, "Too bad. You had C chances and did not find the letter. The letter was X" where Xis the character at position P. Hints: a) if the string has repeated letters (ex: "balloon"), that's okay and it gives the player a better chance of guessing! b) the String methods are always useful : charAt0. .toUpperCase0, lengthO, .replaceAllO, etcStep by Step Solution
There are 3 Steps involved in it
Step: 1
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