Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me to write this code! Objective: In doing this lab you will learn a

ID: 3649988 • Letter: P

Question

Please help me to write this code!

Objective: In doing this lab you will learn about iteration (one of the three basic control mechanisms in programming, the others being sequence and branching). You will also develop a command-line interface for your software.

Specification: Use Java to write and run a guessing game program that will think of a number and invite a user to guess it. After each guess, the game will tell the user if his/her guess was high or low or if they guessed correctly, and then ask the user to guess again. The game will continue to ask for the next guess until either the user guesses correctly or gives up. When the game ends, if the user finally guessed the correct number, the game will tell the user how many guesses were needed and whether the user was a good guesser or not. If the user quits before guessing correctly, he/she will be suitably insulted.

Here are two examples of how the game should work:

Welcome to the Guessing Game.
I am thinking of a number between 0 and 1000.

What is your guess? 25
Good guess, but 25 is too low.

What is your guess? 768
Good guess, but 768 is too high.

What is your guess? 432
Correct! It took you only 3 guesses. You win!!

Or,
Correct, it took you 23 guesses. Don

Explanation / Answer

with Ada.Numerics.Discrete_Random; with Ada.Text_IO; procedure Guess_Number_Feedback is procedure Guess_Number (Lower_Limit : Integer; Upper_Limit : Integer) is subtype Number is Integer range Lower_Limit .. Upper_Limit; package Number_IO is new Ada.Text_IO.Integer_IO (Number); package Number_RNG is new Ada.Numerics.Discrete_Random (Number); Generator : Number_RNG.Generator; My_Number : Number; Your_Guess : Number; begin Number_RNG.Reset (Generator); My_Number := Number_RNG.Random (Generator); Ada.Text_IO.Put_Line ("Guess my number!"); loop Ada.Text_IO.Put ("Your guess: "); Number_IO.Get (Your_Guess); exit when Your_Guess = My_Number; if Your_Guess > My_Number then Ada.Text_IO.Put_Line ("Wrong, too high!"); else Ada.Text_IO.Put_Line ("Wrong, too low!"); end if; end loop; Ada.Text_IO.Put_Line ("Well guessed!"); end Guess_Number; package Int_IO is new Ada.Text_IO.Integer_IO (Integer); Lower_Limit : Integer; Upper_Limit : Integer; begin loop Ada.Text_IO.Put ("Lower Limit: "); Int_IO.Get (Lower_Limit); Ada.Text_IO.Put ("Upper Limit: "); Int_IO.Get (Upper_Limit); exit when Lower_Limit