Ok thanks for that help got it workin now but have a question?

Discussion in 'Software' started by kenny770, Mar 30, 2005.

  1. kenny770

    kenny770 Private E-2

    here is my code:

    import javax.swing.JOptionPane;

    public class Random{

    /**Main Method*/
    public static void main (String[] args) {

    //Declare and intialize variables
    int num1 = (int)(Math.random()*11);
    int num2 = (int)(Math.random()*11);
    int sum = 0;
    sum = num1 * num2;
    int userGuess;

    //Get user input
    String guessString = JOptionPane.showInputDialog(null,"What is " + num1 + "*" + num2 + "?","Project 3",JOptionPane.QUESTION_MESSAGE);

    //Convert user input into a int
    userGuess = Integer.parseInt(guessString);

    //Invoke the checkResult method to check students answer against computers answer
    checkResult(userGuess, sum);

    }
    //Check students answer with checkResult method
    public static void checkResult(int studentAnswer, int correctAnswer){
    if(studentAnswer == correctAnswer)
    JOptionPane.showMessageDialog(null,"Very Good!","Project 3",JOptionPane.INFORMATION_MESSAGE);

    else
    JOptionPane.showMessageDialog(null,"That was incorrect. Try Again","Project 3",JOptionPane.INFORMATION_MESSAGE);
    }
    }

    I now have it running but i need the program to continue to run until the user enters the correct answer should i the incorrect JOptionPane message in a do-while loop instead in the second method are what should i do any help is thankful
     
  2. goldfish

    goldfish Lt. Sushi.DC


MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds