Question: Im trying to write a program that randomly generates a number. Then, the user is to guess the number. The command line Java program to

Im trying to write a program that randomly generates a number. Then, the user is to guess the number.

The command line Java program to input, keep track of, and check user's attempts to guess a randomly generated number. The input portion of the program will be a continuous loop, only breaking out of it when the user either guesses the correct number, or by entering -1 to signify giving up. After each guess, the user will be informed of his guess being too high, too low, or exactly correct. Upon exiting the loop, the user is given feedback of their guesses (amount guessed too low, amount guessed too high, total amount of guesses).

I want to use :

Boolean functions and can it be made using one command line (public static line)?

import java.util.Random; Random rand = new Random(); int value = rand.nextInt(32)+1

This is how the output is supposed to look like:

Guess the number I'm thinking of, from 1-100: 21 Your guess is larger than the random value. Next guess: 5 Your guess is larger than the random value. Next guess: 7 Your guess is smaller than the random value. Next guess: 4 You've guessed correct! Total number of guesses: 4 Smaller Guesses: 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!