subject

Write a program that generates a random number and asks the user to guess what the number is. if the user's guess is higher than the random number, the program should display "too high, try again." if the user's guess is lower than the random number, the program should display "too low, try again." the program should use a loop that repeats until the user correctly guesses the random number. you shall also keep a count of the number of guesses that the user makes. when the user correctly guesses the random number, the program should display the number of guesses. now add another loop to ask the user if he or she wishes to play the guessing game again. if so, the loop should repeat, otherwise it should terminate.
so far, this is what my program looks like, any or suggestions would be greatly appreciated!

// this program generates a random number and askes the user to guess what the number is

import java. util. scanner;
import java. util. random;
public class guessinggame
{
public static void main(string [] args)
{
//create a scanner object to read from the keyboard
scanner kb = new scanner(system. in);
//create a random object
random rand = new random();
//identifier declarations
int num = rand. nextint(100) + 1;
int guess = 0;
int count = 0;
int guesses = 0;
do
{
system. out. println("guess what number i have (1-100)? ");
guess = kb. nextint();
guesses ++;
if(num > guess) {
system. out. println("too high, try again.");
} else if(num < guess) {
system. out. println("too low, try again.");
} else {
system. out. println("you're right, the number is" + num);
system. out. println("you guessed" + guesses + "times");
}
}
while(guess! =num);
}
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 22:00
Technician a says engine assemblies can be mounted longitudinally in a chassis. technician b says engine assemblies can be mounted transversely in a chassis. who is correct?
Answers: 2
question
Computers and Technology, 24.06.2019 07:00
Guys do you know sh27 cause he hacked me : ( pidgegunderson my old user
Answers: 2
question
Computers and Technology, 24.06.2019 15:30
What is the function of compilers and interpreters? how does a compiler differ from an interpreter?
Answers: 2
question
Computers and Technology, 24.06.2019 16:50
7.23 main lab 7 - online shopping cart background this main lab extends the earlier prep lab "online shopping cart part 1". (you should save this as a separate project from the earlier prep lab). you will create an on-line shopping cart like you might use for your on-line purchases. the goal is to become comfortable with setting up classes and using objects. requirements this lab can be done individually or as pair programming. expanded itemtopurchase class (15 points) extend the itemtopurchase class as follows. we will not do unit testing in this lab so we will not be giving you the names of the member functions. create good ones on your own. create a parameterized constructor to assign item name, item description, item price, and item quantity (default values of "none" for name and description, and 0 for price and quantity). additional public member functions set an item description get an item description print the cost of an item - outputs the item name followed by the quantity, price, and subtotal (see example) print the description of an item - outputs the item name and description (see example) additional private data members a string for the description of the item. example output of the function which prints the cost of an item: bottled water 10 @ $1.50 = $15.00 example output of the function which prints the item description:
Answers: 1
You know the right answer?
Write a program that generates a random number and asks the user to guess what the number is. if the...
Questions
question
Mathematics, 03.05.2020 13:41
question
Biology, 03.05.2020 13:41
Questions on the website: 13722363