Results 1 to 7 of 7
  1. #1
    Reiyn is offline Member
    Join Date
    Sep 2008
    Posts
    29
    Rep Power
    0

    Default Math tutor, no errors, nothing appears when run!

    So, I decided to try to build a math tutoring app for my gf's son.
    I have no errors, yet nothing appears when I run it.
    I'm thinking it's something in the try catch block under SetUserChoice, but it looks right to me lol
    Thanks for your help, here's my code thus far:
    Java Code:
    import javax.swing.*;
    public class Main 
    {
        double dRandom1;
        double dRandom2;
        double dRandom3;
        int iNumber1 = (int)(dRandom1 * 100) + 1;
        int iNumber2 = (int)(dRandom2 * 100) + 1;
        int iNumber3 = (int)(dRandom3 * 100) + 1;
        int iOperationChoice;
        int iDoAgain;
        public void SetUserChoice()
        {
            try
            {
            String soperationchoice = JOptionPane.showInputDialog("Press 1 to do Addition\n Press 2 to do Subtraction\nPress 3 to do Multiplication\nPress 4 to do Division\n0 Exits");
            iOperationChoice = Integer.parseInt(soperationchoice);
            }
            catch (
                        NumberFormatException nfe)
                {
                    Main oUser = new Main();
                    oUser.SetUserChoice();
                }
            switch (iOperationChoice)
            {
                case 0: if (iOperationChoice == 0)
                {
                    System.exit(0);
                    break;
                }
                case 1: if (iOperationChoice == 1)
                {
                    GetAddition();
                    break;
                }
                /*case 2: if (iOperationChoice == 2)
                {
                    GetSubtraction();
                    break;
                }
                case 3: if (iOperationChoice == 3)
                {
                    GetMultiplication();
                    break;
                }
                case 4: if (iOperationChoice == 4)
                {
                    GetDivision();
                    break;
                }*/
                default:
                {
                    JOptionPane.showMessageDialog(null, "Value out of range");
                }
            }
        }
        public void GetAddition()
        {
            {
        
            String suseranswer = JOptionPane.showInputDialog("You will have three tries to get each answer correct.\nWhat is the sum of\n " + iNumber1 +"\n" + iNumber2 +"\n" );
            int iUserAnswer = Integer.parseInt(suseranswer);
            int iSum = iNumber1 + iNumber2;
            for (int i = 0; i < 3; i++)
            {
            if (iUserAnswer < iSum)
            {
                JOptionPane.showMessageDialog(null, "That is incorrect, the answer is higher, try again");
                continue;
            }
            else if (iUserAnswer > iSum)
            {
                JOptionPane.showMessageDialog(null, "That is incorrect, the answer is lower, try again");
                continue;
            }
            else if (iUserAnswer == iSum)
            {
                JOptionPane.showMessageDialog(null,"CORRECT!!!!");
                SetContinue();
            } 
            }   
            }
        }
        public void SetContinue()
        {
            try
            {
            String sdoagain = JOptionPane.showInputDialog("Do another?\nPress 0 to exit Addition\nPress 1 to continue Addition");
            iDoAgain = Integer.parseInt(sdoagain);
            }
            catch (
                        NumberFormatException nfe)
            {            
                SetContinue();
            }
            switch (iDoAgain)
            {
            case 0: if (iDoAgain ==0)
            {
                System.exit(0);
                break;
            }
            case 1: if (iDoAgain == 1)
            {
                Main oAddition = new Main();
                oAddition.GetAddition();
                break;
            }
                default:  
            {
            SetContinue();
            }
            }
            
        }
        public Main() 
        {
            Main oUser = new Main();
            oUser.SetUserChoice();       
            
        }
        
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) 
        {     
        }
    }

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    Java Code:
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) 
        {     
        }
    this is why nothing is run...

  3. #3
    Reiyn is offline Member
    Join Date
    Sep 2008
    Posts
    29
    Rep Power
    0

    Default

    AHAHAHA omg I can't believe I did that...I'm going to leave this open because I will be trying to put it in a gui eventually.
    Would I be better off in the long run to use the scanner class you think?

  4. #4
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    If you're doing a GUI it won't use a Scanner. Instead something like JTextField will store the input and allow you to retrieve it through getText()

    If you're doing buttons then StringBuilder is your best bet and just put StringBuilder.append(number) into each number listener or something.
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  5. #5
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    small suggestion... instead of creating new Main objects would not a while loop around the try/catch such as (while(iOperationChoice = 0)) be sufficient
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  6. #6
    Reiyn is offline Member
    Join Date
    Sep 2008
    Posts
    29
    Rep Power
    0

    Default

    Quote Originally Posted by Singing Boyo View Post
    small suggestion... instead of creating new Main objects would not a while loop around the try/catch such as (while(iOperationChoice = 0)) be sufficient
    I thought I had to use this way to get new random numbers generated...and I give the option then of switching from addition to subtraction or whatever the user wishes to do.
    I have it all finished (well running correctly) and realized I should have them in separate classes so that's next.

    Thanks all three of you I will try your suggestions boyo and judas..to be continued lol

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

Similar Threads

  1. Private Java tutor in Houston?
    By antgaudi in forum Jobs Offered
    Replies: 7
    Last Post: 08-11-2009, 05:00 PM
  2. Math Program
    By stlboi in forum New To Java
    Replies: 8
    Last Post: 04-02-2009, 10:34 PM
  3. Replies: 3
    Last Post: 03-08-2009, 02:51 AM
  4. Private Java Tutor Service. One on One.
    By bharatchhajer in forum Java Software
    Replies: 2
    Last Post: 01-26-2009, 06:54 PM
  5. Replies: 3
    Last Post: 07-19-2007, 12:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •