Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How would this code look rewritten without using try and catch commands and using while loops to check for noninterger entries? Instructions are included. ):

How would this code look rewritten without using try and catch commands and using while loops to check for noninterger entries? Instructions are included.

image text in transcribed

"): sport java.ut... CINE: 1 port java.util. Banden public class Guessing Game public atas administrangll agal in AAVI, que 33 Beting que wal; SCANDA NC - Scanner (yutem.in); boolean orect - Talas; Randam rand - RO) ADAPT - Tannexe). A wht 1 ROTTARE) B System.out. que VAT e.Aline) 14 Integer.parseInt(781); qucag - Inlogcu. Dussell (Val): 1 guess > 50 Il es Answer) ! Syatun.out.println(quant la luzous than the scrut sumb"); ) lit (E) System.out.println(quest' isler then the secres numbex" 1 else 50 System.out.printin Yra win! You goed the secret number: +9]; - 52 Errect - trn; 51 catch (ber Format Exceptice ex) [ System.out.println("tainer, RA AAN): coutime 1 System.ext: 62 6.1 length: 1,773 Tine Ln: 4 Col:71 Pos 127 Linix (LF UTF-8 INS deve serca fil. 4. (30 points) Write a number guessing game program named GuessingGanejava The program will generate a secret random number between 1 and 50 inclusivel. You must use the Fendom cless. The program will continue prompting the user to guess the secret number until they guess it correctly. The program ands when the user successfully USSS6S the socist number Every time you prompt the user, add a while loop with the Scanner hasNextint method to make the program robust If the user didn't enter an integer, discard their input and reprompt with "Not an integer,guess again." If the entered valus is outside the range inot from 1-50), reprompt with "Out of range, quoss again: fuse a while loop for this, you will have to add another whils loop to test for non-integer inside the out-of-range loopl. The program should do the following - Punt the user for a guess lan integer velue from 1-50, inclusive While the guess does not equal the secret number: . If the guess is larger than the goncreted random number, tell the user it is larger than the secrct number and reprompt for another guess make sure to check for non-intogor and out-of-range input). . If the guess its smaller than the generated random number, tell the user it is smaller than the secret number and reprompt for another guess Imake sure to check for non-integer and cut-of-range inputi. Once the guess equals the secret number, tell the user that they guessed the secret number and they win! Here is a sample output from running your program Welcome to the Guessing Game Try to guess the socrct number between 1 and 50 liralusivel Your guess? 60 Out of rango, gus again Not en integer quoss again: 30 30 is larger than the secrct number Your guess? 5 5 is smaller than the scoret number Your guess? Out of range, guess again: 10 10 is smaller than the secret hurt Your guess? 20 20 is larger than the secret number Your guess? 15 15 is smaller than the secret number Your guess? 18 You win! You guessed the secret number 18

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

Knowledge Discovery In Databases

Authors: Gregory Piatetsky-Shapiro, William Frawley

1st Edition

ISBN: 0262660709, 978-0262660709

More Books

Students also viewed these Databases questions