Results 1 to 7 of 7
- 04-22-2009, 09:33 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 29
- Rep Power
- 0
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) { } }
- 04-22-2009, 09:38 PM #2
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
this is why nothing is run...Java Code:/** * @param args the command line arguments */ public static void main(String[] args) { }
- 04-22-2009, 09:44 PM #3
Member
- Join Date
- Sep 2008
- Posts
- 29
- Rep Power
- 0
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?
- 04-22-2009, 09:55 PM #4
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.
- 04-23-2009, 01:32 AM #5
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
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!
- 04-24-2009, 04:15 AM #6
Member
- Join Date
- Sep 2008
- Posts
- 29
- Rep Power
- 0
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
- 11-11-2010, 10:28 AM #7
Similar Threads
-
Private Java tutor in Houston?
By antgaudi in forum Jobs OfferedReplies: 7Last Post: 08-11-2009, 04:00 PM -
Math Program
By stlboi in forum New To JavaReplies: 8Last Post: 04-02-2009, 09:34 PM -
What is the difference between Semantic Errors and Logical Errors?
By tlau3128 in forum New To JavaReplies: 3Last Post: 03-08-2009, 01:51 AM -
Private Java Tutor Service. One on One.
By bharatchhajer in forum Java SoftwareReplies: 2Last Post: 01-26-2009, 05:54 PM -
How to make the menu bar objects appears from right to left
By JavaBean in forum AWT / SwingReplies: 3Last Post: 07-19-2007, 11:12 AM


LinkBack URL
About LinkBacks


Bookmarks