Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The user is reprompted in getAndCheckGuess if the user enters an invalid guess. The user should first see the same error message and then is

image text in transcribed
image text in transcribed
image text in transcribed
The user is reprompted in getAndCheckGuess if the user enters an invalid guess. The user should first see the same error message and then is reprompted. Use a while loop to accomplish this Update the main method to call getAndCheckGuess five times. In other words, the user gets five tries to guess the number. After the five tries or after the user guesses the number (whichever comes first) the program should end with one of the following two messages:'Well done!' or 'The number to guess was *The number to guess is assumed to be a number betwee 1 and 20 (but this method doesn't ch * if numberToGuess provided is indeed between 1 and 20). If the user enters a number that not between 1 and 20 (it is less than 1 or greater than 20) then the message to the user will be 'Guess is not valid' and no other message is printed. eparam numberToGuess this is the number the user is required to guess. @return true if the guess is correct and equal to numberToGuess and false otherwise. public static boolean getAndCheckGuess (int numberToGuess) Scanner keyboard = new Scanner (System.in); System.out.printin("Enter your guess: int userGuess userGuess keyboard, nextInt() ; if (userGuess>numberToGuess) ( System.out.println (Too high") else if (userGuess20) System.out.println ("Guess is not valid") else if (userGuess==numberToGuess)( System.out.println ("You guessed it")i else if(userGuess

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions