hey hows it going. ok im having a problem.
this is the question i have to do.
10. in the numberGame class, remove the declorationof luckyNumber the assignment value. Write a setLuckyNumber method to assign to luckNumber a random number between 1 and 25 and write a getLuckyNumber method. in the playTheGame class add an instruction to EXECUTE the setLuckNumber Method at the startof the game and an instrction that will print out luckyNumber at the end.
here the code. i did the first part with the random number(i thin k i did it right). i need help with the part where is says exectute the method of random number. also i ran the prog and everythign works excpt it gives a random number of 0, all the time. hwy? what am i doing wrong?
thnks for the help
-keko-
heres the class’s
public class NumberGame{
//data members
private int luckyNumber;
private int guess;
//method to set guess
public void setGuess(int g){
guess = g;
}
public void setLuckyNumber(){
luckyNumber = (int) (25 * Math.random() + 1);
}
public int getLuckyNumber(){
return luckyNumber;
}
//method to return appropriate message
public String responce(){
if(guess==luckyNumber){
return “You guessed the lucky number”;
}
else if(guess>luckyNumber){
return”Guess to high”;
}
else {
return “Guess to low”;
}
}
}//end method
2nd class
import javax.swing.JOptionPane;
public class PlayTheGame{
public static void main(String args[]){
NumberGame game = new NumberGame();
String str1 = JOptionPane.showInputDialog(“Guess the lucky Number”);
int guess = Integer.parseInt(str1);
game.setGuess(guess);
JOptionPane.showMessageDialog(null, game.responce() + ” ” + getLuckyNumber());
}
}