Enhance the “Random Letter Compare” program from the previous exercise, to make it a Letter Guessing Game. Modifications, - let the first random letter be the computer’s pick of random letter that the user must guess and let the guess be from A…Z (all 26 letters) - remove the display of the random letter (but see below, TESTING and DEBUGGING) - let the second letter be input from the user, so prompt the user for a guess: "Guess which letter: " o to convert console input from String to a char, consider using: guessLetter = scan.next().toUpperCase().charAt(0); // return input character - compare the user’s character against the computer’s pick, to evaluate the correct result: o if the user guessed correctly, display, “You guessed correctly!” o else, if the user’s guess is before the computer’s pick, display, “Oh, too bad, the letter is after.” o else, the user’s guess must be after the computer’s pick, so display, “Oh, too bad, the letter is before.” Run your program to test all possible results. TESTING and DEBUGGING: - to help yourself while testing (since there are so many letters), display the computer’s pick, but comment it out to really play the game - if the computer pick is commented (so it doesn’t display), consider reducing the number of letters (A..D, instead of A..Z) to help making guessing easier 3. Further enhance the Guessing Game program so that it repeats to give the user up to 10 guesses. Modifications, - declare a constant variable to store the maximum number of guesses: static final int MAXGUESSES = 10; (declare this above and outside the main() ) - declare an int variable to count the number of guesses, (which is incremented (++) inside the loop) - after the statement for the computer’s pick, add a loop (while, for, or even do_while) surrounding the user’s input and evaluation statements, o ask the user for a guess letter o increment (++) the guesses counter inside the loop o the condition for the loop is based on both: a) guesses counter hasn’t reach MAXGUESSES iterations, AND b) user’s guess doesn’t match the computer’s pick o display the number of iterations (counter); or the number of remaining iterations (10 – counter) - after the loop, check if the user did not guess correctly, display, “The correct letter is #” (where # is the computer’s pick)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Enhance the “Random Letter Compare” program from the previous exercise, to make it a Letter Guessing Game.
Modifications,
- let the first random letter be the computer’s pick of random letter that the user must guess
and let the guess be from A…Z (all 26 letters)
- remove the display of the random letter (but see below, TESTING and DEBUGGING)
- let the second letter be input from the user, so prompt the user for a guess: "Guess which letter: "
o to convert console input from String to a char, consider using:
guessLetter = scan.next().toUpperCase().charAt(0); // return input character
- compare the user’s character against the computer’s pick, to evaluate the correct result:
o if the user guessed correctly, display,
“You guessed correctly!”
o else, if the user’s guess is before the computer’s pick, display,
“Oh, too bad, the letter is after.”
o else, the user’s guess must be after the computer’s pick, so display,
“Oh, too bad, the letter is before.”
Run your program to test all possible results.
TESTING and DEBUGGING:
- to help yourself while testing (since there are so many letters), display the computer’s pick, but comment it out to
really play the game
- if the computer pick is commented (so it doesn’t display), consider reducing the number of letters (A..D, instead of A..Z)
to help making guessing easier
3. Further enhance the Guessing Game program so that it repeats to give the user up to 10 guesses.
Modifications,
- declare a constant variable to store the maximum number of guesses: static final int MAXGUESSES = 10;
(declare this above and outside the main() )
- declare an int variable to count the number of guesses, (which is incremented (++) inside the loop)
- after the statement for the computer’s pick, add a loop (while, for, or even do_while) surrounding the user’s input and
evaluation statements,
o ask the user for a guess letter
o increment (++) the guesses counter inside the loop
o the condition for the loop is based on both: a) guesses counter hasn’t reach MAXGUESSES iterations, AND
b) user’s guess doesn’t match the computer’s pick
o display the number of iterations (counter); or the number of remaining iterations (10 – counter)
- after the loop, check if the user did not guess correctly, display,
“The correct letter is #” (where # is the computer’s pick)

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education