/** * Too Large Too Small - a number guessing game * * @ShakilaM * @version 0.1, MAy 2018 */ import java.util.*; import java.lang.Math; //Class public class GuessingGame { // instance variables - replace the example below with your own //randomly generated number private int answer; private int counter; private int wrong; //Constructor (name always same as class, no return req) public GuessingGame(int min, int max){ min = 1; max = 10; answer = (int)((Math.random() * ((max-min) + 1)) + min); //counter = wrong; } //end Guessing Game public int wrongAnswers(int counter){ counter = wrong; return counter; }//end WrongAnswers public void playGame(){ //call game method }//end PlayGame public void doYouWantToPlay(){ Scanner answer = new Scanner(System.in); System.out.print("Do you want to play a game?"); String response = answer.nextLine(); if(response.equalsIgnoreCase("no")){ System.out.println("Well, bye then..."); //how to close/quit? } else { System.out.println("Okay, pick a number between 1 and 10..."); randomNumber(); } } public void randomNumber(){ Scanner guess = new Scanner (System.in); int response = guess.nextInt(); int old = 0; do{ if (response == old){ System.out.println("Same same!"); old = response; response = guess.nextInt(); } /**else if(response==answer){ System.out.println("Great job! You're so good at this! Feel free to play again..."); break; }*/ else if(response > answer){ System.out.println("That's too high! Try again..."); wrong = wrong + 1; old = response; response = guess.nextInt(); } else{ System.out.println("Too low. Give it another try..."); wrong = wrong + 1; old = response; response = guess.nextInt(); } } while (response != answer) ; wrong = wrong + 1; old = 0; System.out.println("Great job! You're so good at this! Feel free to play again."); System.out.println("It took you " + wrongAnswers(counter) + " tries!"); counter = 0; doYouWantToPlay(); }//end randomNumber }//end Class