Answered step by step
Verified Expert Solution
Question
1 Approved Answer
E Ensign Homepage C D O 19 LDS 28 63F Clear 5.6 Group Lab-Guessing Game X ensign.instructure.com/courses/14050/assignments/798611?module_item_id=1612090 FAFSA Student Loan ck Credit Karma M
E Ensign Homepage C D O 19 LDS 28 63F Clear 5.6 Group Lab-Guessing Game X ensign.instructure.com/courses/14050/assignments/798611?module_item_id=1612090 FAFSA Student Loan ck Credit Karma M Gmail 2022 Fall Semester Home Announcements Syllabus Modules X Grades People Tutoring Resources Course Hero X iCloud s byu chat page This diagram provides a rudimentary architecture for the guessing game program: TestOut LabSim + Main() Declare variables like Scanner etc. Game do-while loop Course Hero Primary program do-while loop Describe game. Generate random number. Initialize guessCount etc. Numeric Input Validation do-while loop Get guess from user. If guess is valid number, exit validation loop. guess is not valid, print error. Stay in loop. Increment guessCount. Provide hint if guess is not correct. If guess is correct, print number of tries and exit Game loop. Non-Numeric Input Validation do-while loop Ask user if they want to play again. If user input is valid 'Y' or 'N', exit validation loop. If user input is not valid 'Y' or 'N', print error. Stay in loop. If user input was 'N', exit Primary program loop. a I 7:43 PM 10/11/2022 X : E Ensign Homepage C D Q & O 19 LDS 28 63F Clear FAFSA Student Loan ck Credit Karma M Gmail 2022 Fall Semester Home 5.6 Group Lab-Guessing Game X ensign.instructure.com/courses/14050/assignments/798611?module_item_id=1612090 Announcements Syllabus Modules Grades People X Tutoring Resources Example Run Course Hero iCloud byu chat page s I'm thinking of a number between 1 and 100. What is your guess? something Invalid Response! Please enter a whole number. What is your guess? 50 Your guess is too high. Try again. What is your guess? 25 Your guess is too low. Try again. This program is a guessing game. The computer will generate a random integer between 1 and 100. The user will try to guess the number. Let's get started! What is your guess? 33 CORRECT! You guessed it in 3 tries!! Would you like to play again? Not sure Invalid Response! Please answer with a 'Y' or 'N'. Would you like to play again? (Y/N): y X TestOut LabSim + Course Hero This program is a guessing game. The computer will generate a random integer between 1 and 100. The user will try to guess the number Let's get started! OneDrive I Screenshot saved The screenshot was added to your OneDrive. 4) D x 7:43 PM 10/11/2022 X : E Ensign Homepage C D Q & O 19 LDS 28 63F Clear FAFSA Student Loan ck Credit Karma M Gmail 2022 Fall Semester Home 5.6 Group Lab-Guessing Game X ensign.instructure.com/courses/14050/assignments/798611?module_item_id=1612090 Announcements Syllabus Modules Grades People X Tutoring Resources iCloud byu chat page s Invalid Response! Please answer with a 'Y' or 'N' Would you like to play again? (Y/N): y Course Hero I'm thinking of a number between 1 and 100. What is your guess? 50 Your guess is too high. Try again. What is your guess? 25 Your guess is too high. Try again. What is your guess? 12 Your guess is too high. Try again. This program is a guessing game. The computer will generate a random integer between 1 and 100. The user will try to guess the number. Let's get started! What is your guess? 6 Your guess is too high. Try again. What is your guess? 3 Your guess is too low. Try again. X What is your guess? 4 CORRECT! You guessed it in 6 tries!! Would you like to play again? (Y/N): n TestOut LabSim + Course Hero OneDrive I Screenshot saved The screenshot was added to your OneDrive. 4) D x 7:43 PM 10/11/2022 X : E Ensign Homepage C D Q & O 19 LDS 28 63F Clear FAFSA Student Loan ck Credit Karma M Gmail 2022 Fall Semester Home 5.6 Group Lab-Guessing Game X ensign.instructure.com/courses/14050/assignments/798611?module_item_id=1612090 Announcements Syllabus Modules Grades People X Tutoring Resources Course Hero iCloud s byu chat page Package Name: week5 Class Name: GuessingGame X TestOut LabSim + When submitting this lab, submit a java file called "GuessingGame", and create the following structure in Eclipse: Course Hero For this lab, you'll need to use do-while loops and if statements to construct a guessing game. The computer will choose a random number between 1 and 100, and the user will need to guess what the number is. If the user guesses incorrectly, the computer will indicate whether the user's guess was too high or too low. If the user guesses correctly, the computer reports how many tries it took to get the correct answer, and then asks if the user would like to play again. This program will require four do- while loops: The primary do-while loop (outermost) will contain almost all of the code in the program and keep running over and over until the user indicates they no longer wish to play. The game do-while loop is nested inside the primary do-while loop and will keep running over and over again until the user guesses the correct answer and wins the game. As soon as the user wins a game, the program will exit this do-while loop. The numeric input validation do-while loop is nested inside of the game do-while loop and will ensure that the user entered a valid whole number for each guess. The non-numeric input validation do-while loop is located AFTER and OUTSIDE of the game do-while loop. It is only executed after a game is complete and asks the user if they would like to play again. It is nested inside of the primary do-while loop and will ensure that the user entered a valid 'Y' / 'y' / 'N' / 'n' in answer to the "Would you like to play again (Y/N)?" question. a I 7:43 PM 10/11/2022 X : E Ensign Homepage C D Q & O 19 LDS 28 63F Clear FAFSA Student Loan ck Credit Karma M Gmail 2022 Fall Semester Home 5.6 Group Lab-Guessing Game X ensign.instructure.com/courses/14050/assignments/798611?module_item_id=1612090 Announcements Syllabus Modules Grades People X Tutoring Resources Course Hero X iCloud is byu chat page TestOut LabSim //Define the range There are several ways to generate random numbers in Java. We will use the method that utilized the Math library. This will require you to include the following line of code at the top of your program, before your Lab4_6 class declaration. import java.lang.Math; The method, Math.random(), will return a random value between 0 (inclusively) and 1.0 (exclusively). In order to modify this to a range between the integers 1 and some upper limit, we need to multiply the return value of Math.random() by the upper limit of the range we desire and add 1. For example, if we wanted to generate a random number between 1 and 50, we would use the code: double randNum = (Math.random() * 50) + 1; If we wanted to limit the result further to only include integer values we would cast the results to ints. int randNum = (int)(Math.random() * 50) + 1; To make this code more useful and specify both an upper limit and a lower limit, we would modify the code as follows: int randNum = (int)(Math.random() * (1034 - 17 + 1)) + 17; or more generically: + int randNum = (int)(Math.random() * (upperLimit - lowerLimit + 1))+ lowerLimit; For example, if we wanted to generate a random number between 17 and 1034, we would use the code: Course Hero a I 7:43 PM 10/11/2022 X : E Ensign Homepage C D Q & O 19 LDS 28 63F Clear FAFSA Student Loan ck Credit Karma M Gmail 2022 Fall Semester Home 5.6 Group Lab-Guessing Game X ensign.instructure.com/courses/14050/assignments/798611?module_item_id=1612090 Announcements Syllabus Modules Grades People X Tutoring Resources Course Hero int max = 1034; int min = 17; int range = max - min + 1; iCloud s byu chat page TestOut LabSim //Generate a random number between min and max int randNum = (int)(Math.random() * range) + min; X + BIG HINT: When approaching a problem with several nested loops, it is sometimes easier to start with the innermost loops and work outward: Create the numeric input validation loop. Indent the numeric input validation loop and surround it with the game loop. Course Hero Add the non-numeric input validation loop after the game loop. Indent the game loop and the non-numeric input validation loops and surround them with the primary program loop. This diagram provides a rudimentary architecture for the guessing game program: Main() Declare variables like Scanner etc. Primary program do-while loop Describe game. Generate random number. Initialize guessCount etc. a I 7:43 PM 10/11/2022 X :
Step 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