Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Details: You will need to write your guessing game according to the following UM

ID: 3623869 • Letter: D

Question

Details:

You will need to write your guessing game according to the following UML.



-keyboardReader:Scanner

-numberGenerator:Random

+startGame():void

+firstGuessLow(lowestPossible: int):void

+second Guess(miniGuess: int,maxGuess: int):void

+GuessingGame(input: Scanner)





The main method should look like the one below, you may not have more than three lines in the main method

public static void main(String[] args){

Scanner userInput = new Scanner(System.in);

GuessingGame myGame = new GuessingGame(userInput);

myGame.startGame();

}



The GuessingGame constructor should



take its Scanner parameter and assign it to the keyboardReader instance variable.

create a new Random object and assign it to the numberGenerator instance variable.



startGame should



print an invitation for the user to "think of a number from one to 20."



inform the user that your program will try to guess the users number.

generate a random number from 1-20 (inclusive) using the numberGenerator instance variable.

print this number out as your program's initial guess.

ask the user if this is the correct number or if it is high or if it is low.



if the user says the number is high, then call the firstGuessHigh method with that number as a parameter

if the user says the number is low, then call firstGuessLow and again pass the number as a parameter.

if the user says the program is right, celebrate and do nothing more (which will end the program.)

firstGuessHigh

generate a random number from 1 to the parameter

ask the user if this is the correct number or if it is high or if it is low.

if the user says high call secondGuess with 1 as the minGuess and this new number as the max guess

if the user says low, then call secondGuess and use this value as the minGuess and parameter as maxGuess



if the user says the program is right, celebrate, mention you got it in two and do nothing more (which will end the program.)

firstGuessLow should be the inverse of firstGuessHigh, I leave it as an exercise to the students to think about how it works.

secondGuess

generate a random number from minGuess to maxGuess

ask the user if you have it right

if so, celebrate, mention you got it in three and do nothing more (which will end the program.)

if not tell the user that the user won.



Additinal restrictions:

To help you get in the habit of good program writing, I am imposing the following additional restrictions on your program.



You may not have more than the three lines of code that I gave you in the main method

Explanation / Answer

import java.util.*;

import java.util.Random;

public class RandomNumberGuessingGame

{

public static void main(String[] args)

{

int number,GuessNumber;

Scanner keyboard = new Scanner(System.in);

Random random = new Random();

number = random.nextInt(20);

System.out.println("Enter guessing number: " );

do

{

GuessNumber = keyboard.nextInt();

if(GuessNumber > number)

System.out.println(" Too high, try agian ");

else

if(GuessNumber < number)

System.out.println(" Too low, try agian ");

else if(GuessNumber == number )

System.out.println("CONGURTES");

}while(GuessNumber != number);

System.exit(0);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote