I am trying to develop a number guessing game using the Math and Scanner classes. I have two classes, the GuessingGame class and the GuessingGameTester class.

The programs are supposed to randomly generate a number and tell the user too low/high, getting colder/warmer, and if they won/lost. The user has five guesses to guess the number between 0 and 100. If they run out of guesses or guess the correct number, they are asked if they want to play again.


Both classes compile and the tester class returns the correct results, but it will not allow the user to guess again. Instead, it asks the user if they want to play again after one guess. If the user chooses to play again, no matter what number is the user is told that they won.

Can someone please take a look at my code and point me in the right direction? Thanks

Code:
import java.lang.Math;
import java.util.Scanner;

public class GuessingGame
{
	private boolean gameOver;
	private int differential;
	public int newGuess;
	public int currentNumGuesses;
	public int answer;
	private int max;

	public GuessingGame(int max)
	{
		this.answer = (int) (Math.random() * 100);
		max = 5;
		this.answer = answer;
		this.differential = differential;
		this.newGuess = newGuess;
		currentNumGuesses = this.currentNumGuesses;
		gameOver = false; 
	}

	public int newGame(int max)
	{
		gameOver = false;
		differential = 100;
		return answer;		 
	}

	public String guess(int newGuess)
	{
		differential = answer - newGuess;
		String guess = "";
		String closer = "";
		int currentDiff = answer - differential;
		
		for (currentNumGuesses = 0; currentNumGuesses <= 5; currentNumGuesses++)
		{
			if (newGuess == answer)
			{
				guess = "Congratulations! You won!!!";
				newGuess++;
			}
			else if (newGuess < answer && currentDiff > differential)
			{
				guess = "Too Low";
				closer = "Getting Colder";
				newGuess++;
			}
			else if (newGuess < answer && currentDiff < differential)
			{
				guess = "Too Low";
				closer = "Getting Warmer";
				newGuess++;
			}
			else if (newGuess < answer && currentDiff == differential)
			{
				guess = "Too Low";
				closer = "You guessed the same number. Guess Again.";
				newGuess++;
			}
			else if(newGuess > answer && currentDiff > differential)
			{
				guess = "Too High";
				closer = "Getting Colder";
				newGuess++;
			}
			else if(newGuess > answer && currentDiff < differential)
			{
				guess = "Too High";
				closer = "Getting Warmer";
				newGuess++;
			}
			else if(newGuess > answer && currentDiff == differential)
			{
				guess = "Too High";
				closer = "You guessed the same number. Guess Again.";
				newGuess++;
			}
			else if (newGuess < 0 || newGuess > 100)
			{
				guess = "Guess out of range. \n The guess must be between 0 and 100.  \n Guess Again.";
				newGuess++;
			}
			else if (newGuess == answer || currentNumGuesses > max)
			{
				guess = "Game Over. \n";
			}
		} 
		return guess + "\n" + closer;
	}	

	public boolean isGameOver()
	{
		if (newGuess != answer || currentNumGuesses < max)
		{
			gameOver = false;
		}
		else
		{
			gameOver = true;
		}
		return gameOver;
	}

	public int getAnswer()
	{
		return answer;
	}

	public int getDifferential()
	{
	return differential;
	}
}
Code:
import java.lang.Double;
import java.util.Scanner;

public class GuessingGameTester
{
	public static void main(String[] args)
	{
		GuessingGame gameOne = new GuessingGame(5);
		gameOne.answer = (int) (Math.random() * 100);
		System.out.println(gameOne.answer);
					
		System.out.println("Welcome to the Guessing Game");
		System.out.println("Guess a number between 0 and 100");
		System.out.println("Number of guesses allowed: 5"); 

		Scanner input = new Scanner(System.in);
		gameOne.newGuess = input.nextInt();
		String playerGame1 = gameOne.guess(gameOne.newGuess); 
		System.out.println(playerGame1);
		
		boolean gameOver = false;
		while (!gameOver)
		{
			System.out.println("Would you like to play again? Enter Y for yes or N for no.");
			String playerResponse = input.next();
			
			if(playerResponse.equalsIgnoreCase("Y"))
			{
				GuessingGame gameTwo = new GuessingGame(5);
				gameTwo.answer = (int) (Math.random() * 100) +1;
				System.out.println(gameTwo.answer);
								
				System.out.println("Welcome to the Guessing Game");
				System.out.println("Guess a number between 0 and 100");
				System.out.println("Number of guesses allowed: 5");

				gameTwo.newGame(gameTwo.newGuess);
				gameTwo.newGuess = input.nextInt();
				String playerGame2 = gameTwo.guess(gameTwo.newGame(gameTwo.newGuess)); 
				System.out.println(playerGame2);
			}
			else
			{
				System.out.println("Thanks for playing!");  
			}
		}
	}
}