For this assignment you will write the first part of a program that will play a simple "Guess the Number" game. In the full version of this game (which you will write for this week's project) the...

1 answer below »

For this assignment you will write the first part of a program that will play a simple "Guess the Number" game. In the full version of this game (which you will write for this week's project) the program will randomly generate an integer between 1 and 200 inclusive and then will repeatedly ask the user for a guess. If they guess a number that is less than 1 or more than 200 an error message will be printed as a part of this loop. For this lab you will write the piece of the code that checks for this error and ends if the user picks the right number.


Sample OutputThis is a sample transcript of what your program should do. Items in bold are user input and should not be put on the screen by your program. Note that the code for this lab includes a "debugging" output that starts with the word "DEBUG: " that tells you the number that was randomly chosen. In the full version of this program that will be removed, but for this incremental piece your lab submission should include it. (You should get used to having this kind of debugging output in your code that isn't part of the final program but is crucial to ensuring that each incremental piece is working properly before you move onto the next part of the program).


If the user enters an invalid choice, your code should inform them that their choice was invalid and ask them to guess again.


Enter a random seed: 99 DEBUG: The number picked is: 188  Enter a guess between 1 and 200: 259 Your guess is out of range.  Pick a number between 1 and 200. That is not the number.  Enter a guess between 1 and 200: -1 Your guess is out of range.  Pick a number between 1 and 200. That is not the number.  Enter a guess between 1 and 200: 88 That is not the number.  Enter a guess between 1 and 200: 188 Congratulations!  Your guess was correct!  I had chosen 188 as the target number. You guessed it in 4 tries.


Answered 1 days AfterSep 16, 2021

Answer To: For this assignment you will write the first part of a program that will play a simple "Guess the...

Aditya answered on Sep 18 2021
126 Votes
import java.util.Random;
import java.util.Scanner;
public class guess {
public static void ma
in(String[] args) {
Scanner scanner = new Scanner(System.in);
int guessNumber = 0, seed, randomNumber;
int numberOfTries = 0;
System.out.print("Enter a random seed: ");
seed = scanner.nextInt();
Random random...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here