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

Please pick a number between 1-10 and I, the computer, will guess it. Is the num

ID: 3633519 • Letter: P

Question

Please pick a number between 1-10 and I, the computer, will guess it.

Is the number 6 ? n
Is my guess larger or smaller than your number ?smaller
Is the number 3 ? n
Is my guess larger or smaller than your number ?larger
the number 5 ? y
I got your number 5 in 3 guess(es)!

explanation to help:. You need to work with random number generation from a given range. In order to generate a random number within the range [min, max] inclusive, we can simply use the Random class as:
Random rand = new Random();
int myRandomNumber = rand.nextInt(max - min + 1) + min;

Here, (max - min + 1) is the size of range.

For example, to generate a random integer number between 22 and 30 inclusive, we write
int myRandomNumber= rand.nextInt(9) + 22;

Explanation / Answer

// The "Random_Number_Guesser" class. import java.awt.*; import hsa.Console; public class Random_Number_Guesser { static Console c; public static void main (String[] args) { c = new Console (); int long number = (Math.round(Math.random() * 100)); int guess; while (on_off == 1) { c.println ("Guess a number between 1 and 101!"); guess = c.readInt (); if (number > guess) { c.println ("Nope, too low."); } if (number