Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

T The program seems to have a bug! If I enter a number that is greater then 200 and then enter a number that is

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedT

image text in transcribedThe program seems to have a bug! If I enter a number that is greater then 200 and then enter a number that is less then 1 it doesn't print out that the number is out of range!

GuessANumber [Java Application] /Library/Java/JavaVirtual Machines/jdk-13.0.1.jdk/Conten Enter a random seed: 1 Enter a quess between 1 and 200: -1111 Your guess is out of range. Pick a number between 1 and 200. Your guess was too low - try again. Enter a guess between 1 and 200: 10, Your guess was too low - try again. Enter a guess between 1 and 200: 150 Your guess was too low - try again. Enter a guess between 1 and 200: 100000 Your guess is out of range. Pick a number between 1 and 200. Your guess was too high - try again. Enter a guess between 1 and 200: -1111 Your guess was too low - try again. Enter a guess between 1 and 200: import java.util. Random; import java.util.Scanner; public class GuessANumber { public static void main(String[] args) { Scanner scan = new Scanner (System.in); Random ran = new Random(); System.out.print("Enter a random seed: "); int seed = scan.nextInt(); ran.setSeed (seed); int nxt = ran.nextInt(200) + 1; System.out.print("Enter a guess between 1 and 200: "); System.out.print(""); int guess = scan.nextInt(); int numGuess = 1; if (guess == nxt) { System.out.println("Congratulations! Your guess was correct!"); System.out.println(""); System.out.println("I had chosen " + nxt + " as the target number."); System.out.println("You guessed it in " + numGuess + "tries."); System.out.println("That was impossible!" while (guess != nxt) { if(guess > 200) { System.out.println("Your guess is out of range. Pick a number between 1 and 200."); if (guess 200) { System.out.println("Your guess is out of range. Pick a number between 1 and 200."); if (guess nxt) { System.out.println("Your guess was too high - try again."); System.out.println(""); System.out.print("Enter a guess between 1 and 200: "); numGuess = numGuess + 1; guess = scan.nextInt(); if (guess 3 && numGuess 3 && numGuess 10) { System.out.println("Congratulations! Your guess was correct!"); System.out.println(""); System.out.println("Congratulations! Your guess was correct!" System.out.println(""); System.out.println("I had chosen " + nxt + " as the target number."); System.out.println("You guessed it in " + numGuess + " tries."); System.out.println("Not bad, not bad..." if (numGuess = 8) { System.out.println("Congratulations! Your guess was correct!"); System.out.println(""); System.out.println("I had chosen " + nxt + " as the target number. "); System.out.println("You guessed it in " + numGuess + "tries.") System.out.println("That was not very impressive." if (numGuess == 9 || numGuess == 10) { System.out.println("Congratulations! Your guess was correct!"); System.out.println(""); System.out.println("I had chosen " + nxt + " as the target number. " System.out.println("You guessed it in " + numGuess + "tries."); System.out.println("Are you having any fun at all?"); pohlen if (numGuess > 10) { System.out.println("Congratulations! Your guess was correct!"); System.out.println(""); System.out.println("I had chosen " + nxt + " as the target number. " System.out.println("You quessed it in " + numGuess + "tries." System.out.println("Maybe you should play something else.") scan.close()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions