Re: question about my applet
Again I ask- where are you stuck? I'm really not sure what you don't understand. You have an Applet, you know what you have to do... I honestly don't know what the problem is.
Recommended reading: Returning a Value from a Method (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
Re: question about my applet
stuck at generating the number from 100 -150.
Re: question about my applet
ok i have this now
Code Java:
public int generateQuestion()
{
Random rand = new Random();
int num = rand.nextInt(51) + 101;
questionLabel.setText( "Guess oil price (100 - 150)" );
return num;
}
public void displayMessage()
{
if ( guessPrice == predictPrice)
{
showStatus ( "You are right." );
predictPrice = generateQuestion();
}
else if (guessPrice >= predictPrice);
showStatus ( "Too low." );
predictPrice = generateQuestion();
}
}
{
}
Re: question about my applet
In your other thread, you said you found an algorithm for generating a random number. Where did you get stuck trying to implement that?
Hint: Math.random() gives you a random decimal between 0 (inclusive) and 1 (exclusive). The API is your friend.
Re: question about my applet
...so now is your problem solved? You win the prize for most confusing poster of the day.
Re: question about my applet
no cuz im not sure on the return if i leave num as the return does it stay the same number until user guess the right price and my showstatus says "your right"
Re: question about my applet
If I'm interpreting your question correctly, the answer is no. Every time you call the generateQuestion() function, you'll return a different random number. But then again, I might be misunderstanding what you're asking.
Re: question about my applet
yes that what im asking. i need the number to stay the same so if i have an instance variable, called int randomNumber. and had this returned would it stay the same?
Re: question about my applet
What happened when you tried that? :D