Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import java.util.Scanner; public class GuessNumberApp { public static void main ( String [ ] args ) { Game game = new Game ( ) ;
import java.util.Scanner;
public class GuessNumberApp
public static void mainString args
Game game new Game;
game.displayWelcomeMessage;
Scanner scanner new ScannerSystemin;
New game loop
while true
game.generateNumberToBeGuessed;
game.displayPleaseGuessMessage;
Inner game loop
while true
int userGuess scanner.nextInt;
game.makeGuessuserGuess;
if gameisCorrectGuess
game.displayCorrectGuessMessage;
break; Exit inner loop if guess is correct
else
displayGuessFeedbackgamegetNumber userGuess;
game.displayGuessAgainMessage;
Ask if the user wants to play again
System.out.printlnDo you want to play again? Type y for yes, n for no;
String playAgain scanner.nexttoLowerCase;
if playAgainequalsn
break; Exit outer loop if user types n
scanner.close;
Method to display feedback based on the difference between the guess and the number to be guessed
private static void displayGuessFeedbackint numberToGuess, int userGuess
int difference Math.absnumberToGuess userGuess;
if difference
System.out.printlnWay too userGuess numberToGuess "high" : "low" Guess again.";
else
System.out.printlnToo userGuess numberToGuess "high" : "low" Guess again.";
in java
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started