I think I've got it almost, so I can only get rid of some exceptions The program gives me when I Attempt to run it. Here I have the code:
Package randommath game; Import java.awt.event.ActionEvent; Import java.awt.event.ActionListener; Import javax.swing *; Public class randommath {public static zero main (string [] args) {RandomProblem Generator randomProblems = new RandomProblem Generator (10); Final int number problems = 10; Int correctScore = 0; Zpean panel = new zpn (); Integer answer; Int correct answer; JLABEL [] MathPrablemes = New JLABEL [Number Problems]; Ultimate Jettextfield [] Mathematical Area = New JTextField [Numbers]; Jlabble [] right no = new jlabell [numbers]; Final JLab score = new JLABEL (rightcore + "/ 10"); Pocket-submit = new pocket ("submit"); For (int i = 1; i & lt; = number problems; i ++) {last int x = randomProblems.createNumberX (); Last Int Y = Random Pub. Math Problems [i] = New JLabel ("+ +" * "+ Y +" = "); Math Orientation [i] = New JTextField (); Answer = Integer.parseInt (mathAnswers [i] .getText () Correct reply = x * y; if (answer == correct answer) {right yes not [i] = new jlabel ("right answer; good work!") CorrectScore = correctScore + 1;} and {not right} [I] = New JLabel ("wrong answer, try again!");} Panel.ad (math problems [i]); panel.add (mathAnswers [i]); panel.add (correctYesNo [i]); } Final integer temp = correctScore; Submit.addActionListener (New Executioner) {@ Override Public Wide Action Performed (Action Score: "Score:" + "Temporary +" / 10 ");}}); panel.add (presented); panel.add (Score); Jeffram GameFrame = New JFram ( GameFrame.setTitle ("Random Math Game"); GameFrame.setSize (150, 150); gameFrame.setVisible (true); gameFrame.setContentPane (panel);}} and These exceptions are giving me this when I run it:
Exception in the formula "main" java.lang.NumberFormatException: string for input: "java.lang.NumberFormatException.forInputString (NumberFormatException.java:65) java.lang.Integer.parseInt (Integer.java:504) at java.lang.Integ RandomMathGame.RandomMathGame.Main (RandomMathGame.java33) Java results: 1 I am crunched for the time, so any help is available on er.parseInt (Integer.javaration27) Would be greatly appreciated.
string answerStr = mathAnswers [i] .getText (); If (answerStr.isEmpty ()) {Not true yes [i] = New JLabel ("No valid answer / answer field blank!"); } And {answer = integer. Paracet (North STR); Correct answer = x * y; // The rest of your code goes here} Hope this helps!
Comments
Post a Comment