My game is compiling and read's right (in my head) but doesn't appear to work, any help is highly appreciated, thank you.
Source code. More specifically, I think that it's properly getting the random number, but the guess prompt is not appearing, probably because of my while(random!=number) line?
import javax.swing.JOptionPane;
import java.util.Random;
/**
* High-Low (HiLo) game.
*
* @author
* @version 11/18/2010
*/
public class HiLo
{
String randomNumber = "";
int random;
String userNum = "";
int number;
/**
* Asks player if he wants to play, gets random number, gets user guess, checks the users guess, asks to repeat.
*
*/
public void play()
{
getRandom();
while(random!=number)
{
getGuess();
checkGuess();
}
}
/**
* Gets the users guess.
*/
public int getGuess()
{
userNum = JOptionPane.showInputDialog ("Please Guess the number");
int number = Integer.parseInt(userNum);
return number;
}
/**
* Gets a random number between 0 and 100
* int named random
*/
public int getRandom()
{
Random randomNumber = new Random();
int random = randomNumber.nextInt(101);
return random;
}
/**
* Checks to see if the user's guess is an integer, between 0 and 100, and returns if
* they're guess is too high or too low.
*/
public void checkGuess()
{
if (number==random)
JOptionPane.showMessageDialog(null, "You Win!");
else if (number<random)
JOptionPane.showMessageDialog(null, "Too low, guess again!");
else if (number>random)
JOptionPane.showMessageDialog(null, "Too high, guess again!");
}
}
Edited by: 811146 on Nov 18, 2010 3:11 PM