Question: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
