E Ensign Homepage C D O 19 LDS 28 63F Clear 5.6 Group Lab-Guessing Game X...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 : 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 :
Expert Answer:
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
HR Trends Institute https://hrtrendinstitute.com/(Links to an external site.) HR Technology Discuss IT changes that you have experienced at work such as new cash register or inventory system or...
-
International Inc. operates and franchises pizza delivery and carryout restaurants worldwide. The following is an alphabetical list of accounts and amounts reported in a recent year's set of...
-
Explain why you agree, or disagree, with the following statements: "It is stupid to treat employee stock options as an expense. They never require an outlay of cash by the company."
-
Jonathan Law Firm performed legal services for a client who could not pay immediately. The business expected to collect the \($9,000\) the following month. Later, the business received \($5,400\)...
-
After watching the video on India and Chinas economies, discuss the following: 1. What impact do the political systems of each country have on their efforts toward globalization? 2. How do IP rights...
-
Present an overview of Verizon's financial performance over the past few years. Include key metrics such as revenue, net income, and earnings per share. - Provide a brief analysis of Verizon's...
-
A bank categorizes its customers into one of three groups based on their banking habits. A random sample of 30 customers from each group was selected, and the number of times each customer visited...
-
A small company produces and sells two types of products: product A and product B. The company has a total of 300 units of labor and 100 units of capital available for production. The production...
-
D. Let y, be the vertical location of a ball, and y, the vertical location of a hand. Write down a equation that means: "The ball is 2 meters above the hand."
-
Lite Packs Company (LPC) makes and sells ultra-light backpacks. During Year 1, LPC sold 1,600 backpacks for $51 each. Each backpack has a variable cost of $28 and the company had total fixed cost...
-
Inventory balances for the James Enterprises in February 2011 are as follows: February 1, 2011 February 28, 2011 Raw materials $ 27,000 $21,000 Work in process 48,000 37,200 Finished goods 108,000...
-
Based on "The Next Management Breakthrough: EPM, Non-GAAP Measures and KPIs in a Digital World," https://mydigitalpublication.com/publication/?i=652870&ver=html5&p=32 What are some challenges of...
-
A company has two service departments (S1 and S2) and two production departments (P1 and P2).Departmental data for August 2018 were as follows: [S1 and S2] Cost incurred:P54,000, P36,000 Service...
-
(10 points) An assertion specifies that a program always satisfies a certain condition at a particular point during its execution. The assert function in C takes as input an expression; the program...
-
Decades after the event, Johnson & Johnson (J&J), the 130-year-old American multinational, is still praised for swiftly The company indicated that its response was based on the expectations set forth...
-
Larry Gaines, age 42, sells his personal residence on November 12, 2012, for $144,000. He lived in the house for 7 years. The expenses of the sale are $10,500, and he has made capital improvements of...
-
Brian and Kim have a 12-year-old child, Stan. For 2012, Brian and Kim have taxable income of $52,000, and Stan has nonqualifying dividend income of $4,500 and investment expenses of $250. No election...
-
How much of each of the following prizes or awards is taxable? a. Cheline received a $50,000 gift bag at the Oscars in 2012. b. Jon received a gold watch worth $350 for 25 years of service to his...
-
Acorn Growth Limited is a small technology company listed on the TSX. To conserve cash, the company frequently settles obligations through the issuance of rights and options. Shares are now trading...
-
Convertible Debt, Three Cases: The following cases are independent: Case A On 1 November 20X1, Bertha Builders Limited issued a convertible bond that was convertible in 15 years' time into 78,000...
-
NewTech Ltd. has a 31 December fiscal year-end. The company issued convertible bonds on 1 July 20X4. The \(\$ 5,000,000\) bonds pay annual interest of \(8 \%\) each 30 June and mature on 30 June...
Study smarter with the SolutionInn App