Answered step by step
Verified Expert Solution
Question
1 Approved Answer
IS 2031: LE 4.1 Sections 001, 002, 003 Grading Requirements: During lab class, enter your name on the sign-up sheet for Lab Day |DUE DATE
IS 2031: LE 4.1 Sections 001, 002, 003 Grading Requirements: During lab class, enter your name on the sign-up sheet for Lab Day |DUE DATE grading when your assignment is in gradable condition. Files Posted with Instructions: .LE 4.1 SAMPLE OUTPUT pdf M 2/25/19 Purpose: To code a for and do-while loops, and reinforce if-else, and nested control structures o Test your program using all the data and scenarios in the sample output. LE41CodeSegments.pdf Prep Work: Chapters 2, 3, and 4, and Shepherd's PowerPoint slides. Look at the sample output in conjunction with the instructions to work out your logic. Instructions: Create a program that will allow a child to test his/her skills with adding integers from 1-10 that are generated randomly. Give the child 3 tries to answer correctly but even when the 3 tries are up, let the child decide whether to continue playing. Use a do-while loop to control the playing. Use a for loop to control the number of tries. The loops are nested. The do-while is better suited as the outer loop. Look at the sample output for prompt, output messages, and spacing requirements. 1. Use a sentinel-controlled do-while to control the playing. 2. Set the counter-control variable of the for loop to 2 ancrement through zero to account for the 3 tries, but more importantly to reflect the number of tries left. answer, so the for loop is exited a. "YAAAYYYY!! :) You are SOoo smart!" when the child enters a correct 3. Make sure to set the counter-control variable to -1 when the child enters the correct 4. Use if-else and nested if-else structures to properly print the messages answer. You don't need to print the double quotes in the message b. "Awww :( You have 9 tries left.", when the child enters an incorrect answer where the 9 represents the number of tries left and when the number left is greater than 1; gtherwise.print "AWWW ( You have 9 try left." when the child enters an incorrect answer and the number left is 1. You don't need to print the double quotes in the message c. "OH NOOO! You are out of tries!" when there are no more tries left. You don't need to print the double quotes in the message 5. Print "Bye Xxxxxxxx, come back soon!!" where the Xs represents the child's name 6. Import the Random class from javautil a. Create a Random object: Random random- new Random); b. Generate a random value for each of the integers in the summation equation. In the code below you're range of randomly generated values will be from 0-10 (11 is not part of the range): i. num1 random.nextint( 11) il. num2 - random.nextint(11); 7. Code System.exit(0) only once at the end of main(). r*"CORRECT 1ST TRY NOT PART OF OUTPUT What is your name? Suzie Hi Suzie! Let's ADD numbers! You have 2 tries left 8110 AWWW: You'll have 3 tries to get it right! 2+3 2 5 YAAAYYYY) You are SOO0 smart! You want to play again? y You have 1 try left 10 +5 12 OH NOOO! :( You are out of tries! You want to play again? n Bye Suzie, come back soon!!! INCORRECT AFTER 2 TRIES NOT PART OF OUTPUT Hi Suziel Let's ADD numbers! You'll have 3 tries to get it right! AWWW: You have 2 tries left AWWW: You have 1 try left 7+9 16 YAAAYYYYIII :You are SOO0 smart! You want to play again? y ALL INCORRECT NOT PART OF OUTPUT Hi Suzie! Let's ADD numbers! You'll have 3 tries to get it right! 67 11 Awww
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