Identifier expected and Illegal start of Expression errors

Thread Solved

Join Date: Apr 2008
Posts: 108
Reputation: christiangirl is an unknown quantity at this point 
Solved Threads: 1
christiangirl christiangirl is offline Offline
Junior Poster

Identifier expected and Illegal start of Expression errors

 
0
  #1
Jan 13th, 2009
Hello,
I am getting Identifier expected and Illegal start of Expression erros in this code:
  1.  
  2.  
  3. //"Math is our Game" - A math testing program for First through Fourth grade students
  4.  
  5. //Import GUI packages
  6.  
  7.  
  8. import javax.swing.*;
  9. import BreezySwing.*;
  10. import java.awt.*;
  11. import java.util.Random;
  12. //import TurtleGraphics.*;
  13.  
  14. public class Math extends GBFrame
  15. {
  16.  
  17. //declare variables for the window objects
  18.  
  19. private JLabel greetingLabel;
  20. private JLabel additionLabel;
  21. private JLabel subtractionLabel;
  22. private JLabel multiplicationLabel;
  23. private JLabel divisionLabel;
  24. private JLabel randomLabel;
  25. private JLabel grade1Label;
  26. private JLabel grade2Label;
  27. private JLabel inputLabel;
  28. private JLabel gradeLabel;
  29. private JLabel questionLabel;
  30.  
  31. private JTextField greetingField;
  32. private JTextField additionField;
  33. private JTextField subtractionField;
  34. private JTextField multiplicationField;
  35. private JTextField divisionField;
  36. private JTextField randomField;
  37. private JTextField grade1Field;
  38. private JTextField grade2Field;
  39. private JTextField inputField;
  40. private JTextField questionField;
  41.  
  42. private JButton greetingButton;
  43. private JButton additionButton;
  44. private JButton subtractionButton;
  45. private JButton multiplicationButton;
  46. private JButton divisionButton;
  47. private JButton randomButton;
  48. private JButton grade1Button;
  49. private JButton grade2Button;
  50. private JButton grade3Button;
  51. private JButton grade4Button;
  52. private JButton inputButton;
  53. private JButton quitButton;
  54. private JButton questionButton;
  55. /*int generator1=0;
  56. int generator2=0;
  57. int generator3=0;
  58. int generator4=0;*/
  59.  
  60. JTextArea greetingArea;
  61.  
  62. Random generator = new Random(5);
  63. //constructor
  64. public Math()
  65. {
  66. setUp();
  67. }
  68.  
  69. //Open greeting screen with welcome and Start button
  70. public void setUp()
  71. {
  72. greetingLabel = addLabel("Greeting", 1, 1, 1, 1);//greetingLabel.setText("Greeting"); //= addLabel ("Greeting" ,1,1,1,1);
  73. greetingArea = addTextArea("Welcome to Math is our Game, \na math skills program by \nNine Fingers and Ten Toes Software, Inc.", 2, 3, 3, 3);
  74. greetingButton = addButton ("Start" ,1,3,1,1);
  75. }
  76.  
  77. //Button clicked to start game
  78.  
  79. public void buttonClicked(JButton buttonObj)
  80. {
  81. this.setVisible(false);
  82. math3 test = new math3();
  83. test.setVisible(true);
  84. test.setSize(500, 500);
  85.  
  86. //First grade selected
  87.  
  88. //public void buttonClicked (JButton button)
  89. //{
  90. if (buttonObj == grade1Button)
  91. {
  92. JOptionPane.showMessageDialog(null, "Hi");
  93. //Generate numbers for First Grade problem
  94.  
  95. int generator1 = generator.nextInt(5);
  96. int generator2 = generator.nextInt(5);
  97.  
  98. //Select type of problem
  99.  
  100. //instantiates and add window objects to the window
  101.  
  102.  
  103. }
  104.  
  105. //public void buttonClicked (JButton buttonObj)
  106.  
  107.  
  108. //{
  109.  
  110. //local variables
  111.  
  112. Math2 math1 = new Math2();
  113.  
  114. //determine which button was clicked
  115.  
  116. if (buttonObj == grade2Button)
  117.  
  118. {
  119.  
  120. //setting and getting the numbers for the equations
  121.  
  122. math1.setaddition(Double.parseDouble(additionField.getText()));
  123. //subtractionField.setNumber(math1.getsubtraction());
  124. //math1.setmultiplication(Double.parseDouble(multiplicationField.getText()));
  125. //divisionField.setNumber (math1.getdivision());
  126. //math1.setrandom(randomField.getText());
  127. }
  128. }
  129.  
  130. class math3 extends GBFrame
  131. {
  132. //Select grade level - Instantiate and add window objects to grade level window
  133. JLabel gradeLabel = addLabel("Please select grade level of math problem.", 1, 1, 1, 1);// ,1,1,1,1);
  134. JButton grade1Button = addButton ("First Grade" ,1,1,1,1);
  135. JButton grade2Button = addButton ("Second Grade" ,2, 1,1,1);
  136. JButton grade3Button = addButton ("Third Grade" ,3,1,1,1);
  137. JButton grade4Button = addButton ("Fourth Grade" ,4,1,1,1);
  138. JButton quitButton = addButton ("Quit" ,5,1,1,1);
  139. JButton gobackButton = addButton ("Revert Back" ,6,1,1,1);
  140.  
  141. public void buttonClicked(JButton buttonObj)
  142. {
  143.  
  144. if (buttonObj == quitButton)
  145. System.exit(0);
  146.  
  147. if (buttonObj == gobackButton)
  148. {
  149. //Select grade level - Instantiate and add window objects to grade level window
  150.  
  151. math3 s = new math3();
  152.  
  153. gobackButton = addButton ("Revert Back" ,6,1,1,1);
  154.  
  155. }
  156.  
  157.  
  158. if (buttonObj == grade1Button)
  159. {
  160.  
  161. addButtons P = new addButtons();
  162.  
  163. this.setVisible(false);
  164. P.setVisible(true);
  165. P.setSize(700, 700);
  166.  
  167. }
  168. }
  169. }
  170. public static void main(String [] args)
  171. {
  172. Frame frm = new Math();
  173. frm.setSize(500,500);
  174. frm.setVisible(true);
  175.  
  176. }
  177.  
  178. class Math2
  179.  
  180. {
  181.  
  182. private double Mathsubtraction;
  183.  
  184. public void setaddition(double math)
  185.  
  186. {
  187.  
  188. Mathsubtraction = math;
  189.  
  190. }
  191.  
  192. public double setsubtraction(double math)
  193.  
  194. {
  195.  
  196. return Mathsubtraction;
  197.  
  198. }
  199.  
  200. public double getsubtraction()
  201.  
  202. {
  203.  
  204. return Mathsubtraction;
  205.  
  206. }
  207.  
  208. public double getaddition()
  209.  
  210. {
  211. double Mathaddition = 0;
  212.  
  213. return Mathaddition;
  214.  
  215. }
  216.  
  217. String getdivision() {
  218. throw new UnsupportedOperationException("Not yet implemented");
  219. }
  220.  
  221. void setdivision(double parseDouble) {
  222. throw new UnsupportedOperationException("Not yet implemented");
  223. }
  224.  
  225. void setmultiplication(double parseDouble) {
  226. throw new UnsupportedOperationException("Not yet implemented");
  227. }
  228.  
  229. void setrandom(double parseDouble) {
  230. throw new UnsupportedOperationException("Not yet implemented");
  231. }
  232.  
  233. void getrandom() {
  234. throw new UnsupportedOperationException("Not yet implemented");
  235. }
  236.  
  237. }
  238. /*
  239.  * To change this template, choose Tools | Templates
  240.  * and open the template in the editor.
  241.  */
  242.  
  243.  
  244. /**
  245.  *
  246.  * @author Tyler
  247.  */
  248. class math2 {
  249.  
  250. void setaddition(double parseDouble) {
  251. throw new UnsupportedOperationException("Not yet implemented");
  252. }
  253.  
  254. }
  255.  
  256. /*
  257.  * To change this template, choose Tools | Templates
  258.  * and open the template in the editor.
  259.  */
  260. /**
  261.  *
  262.  * @author TBoden
  263.  */
  264. class addButtons extends GBFrame
  265. {
  266. JLabel additionLabel = addLabel ("Addition" ,1,2,1,1);
  267. JLabel subtractionLabel = addLabel ("Subtraction" ,1,3,1,1);
  268. JLabel multiplicationLabel = addLabel ("Multiplication" ,1,4,1,1);
  269. JLabel divisionLabel = addLabel ("Division" ,1,5,1,1);
  270. JLabel randomLabel = addLabel ("Random" ,1,6,1,1);
  271. JLabel gobackLabel = addLabel ("Revert Back" ,1,7,1,1);
  272.  
  273. JTextField additionField = new JTextField("0");
  274. JTextField subtractionField = new JTextField("0");
  275. JTextField multiplicationField = new JTextField("0");
  276. JTextField divisionField = new JTextField("0");
  277. JTextField randomField = new JTextField("0");
  278. JTextField gobackField = new JTextField("0");
  279.  
  280. JButton additionButton = addButton ("1+1" ,1,5/3,1,1);
  281. JButton subtractionButton = addButton ("1-1" ,4,1,1,1);
  282. JButton multiplicationButton = addButton ("1*1" ,5,1,1,1);
  283. JButton divisionButton = addButton ("1/1" ,6,1,1,1);
  284. JButton randomButton = addButton ("Random Equation" ,7,1,1,1);
  285. JButton gobackButton = addButton ("Revert Back" ,8,1,1,1);
  286.  
  287. public void buttonClicked(JButton buttonObj)
  288. {
  289.  
  290. if (buttonObj == additionButton)
  291. {
  292. Math4 m = new Math4();
  293.  
  294. this.setVisible(false);
  295. m.setVisible(true);
  296. m.setSize(700, 700);
  297. }
  298. if (buttonObj == subtractionButton)
  299. {
  300.  
  301. Math5 m = new Math5();
  302.  
  303. this.setVisible(false);
  304. m.setVisible(true);
  305. m.setSize(700, 700);
  306. }
  307.  
  308. if (buttonObj == multiplicationButton)
  309. {
  310.  
  311. Math6 m = new Math6();
  312.  
  313. this.setVisible(false);
  314. m.setVisible(true);
  315. m.setSize(700, 700);
  316. }
  317.  
  318. if (buttonObj == divisionButton)
  319. {
  320.  
  321. Math12 m = new Math12();
  322.  
  323. this.setVisible(false);
  324. m.setVisible(true);
  325. m.setSize(700, 700);
  326.  
  327. }
  328.  
  329. if (buttonObj == randomButton)
  330. {
  331.  
  332. Math7 m = new Math7();
  333.  
  334. this.setVisible(false);
  335. m.setVisible(true);
  336. m.setSize(700, 700);
  337.  
  338. }
  339.  
  340. }
  341.  
  342.  
  343. class Math12 extends GBFrame{
  344. Random generator = new Random();
  345.  
  346. private JButton SubmitButton = addButton ("Submit Answer" ,1,9/8,1,1);
  347. int generator1 = generator.nextInt(20)+1/2;
  348. int generator2 = generator.nextInt(20)+1/2;
  349. int answer = generator1/generator2;
  350.  
  351. JTextField answerField = addTextField("" ,3/2,2,1,1);
  352.  
  353. JLabel questionLabel = addLabel(generator1 + "/" + generator2 + "=" ,1,30/23,20,20);
  354.  
  355. }
  356.  
  357. class Math4 extends GBFrame{
  358.  
  359. public void additionClicked()
  360. {
  361. Random generator = new Random();
  362.  
  363.  
  364. private JButton SubmitButton = addButton ("Submit Answer" ,1,9/8,1,1);
  365. int generator1 = generator.nextInt(9)+1;
  366. int generator2 = generator.nextInt(9)+1;
  367. int answer = generator1+generator2;
  368.  
  369. JTextField answerField = addTextField("" ,3/2,2,1,1);
  370.  
  371. JLabel questionLabel = addLabel(generator1 + "+" + generator2 +"=" ,1,30/23,20,20);
  372.  
  373. if (answer == 1)
  374. {
  375.  
  376. }
  377. }
  378.  
  379.  
  380. }
  381.  
  382.  
  383. class Math6 extends GBFrame{
  384. Random generator = new Random();
  385.  
  386. private JButton SubmitButton = addButton ("Submit Answer" ,1,9/8,1,1);
  387. int generator1 = generator.nextInt(5)+1;
  388. int generator2 = generator.nextInt(5)+1;
  389. int answer = generator1*generator2;
  390.  
  391. JTextField answerField = addTextField("" ,3/2,2,1,1);
  392.  
  393. JLabel questionLabel = addLabel(generator1 + "*" + generator2 + "=" ,1,30/23,20,20);
  394.  
  395. }
  396.  
  397. class Math5 extends GBFrame{
  398.  
  399. Random generator = new Random();
  400.  
  401. private JButton SubmitButton = addButton ("Submit Answer" ,1,9/8,1,1);
  402. int generator1 = generator.nextInt(9)+1;
  403. int generator2 = generator.nextInt(9)+1;
  404. int answer = generator1-generator2;
  405.  
  406. JTextField answerField = addTextField("" ,3/2,2,1,1);
  407.  
  408. JLabel questionLabel = addLabel(generator1 + "-" + generator2 + "=" ,1,30/23,20,20);
  409.  
  410. }
  411. class Math7 extends GBFrame{
  412.  
  413. Random generator = new Random();
  414.  
  415. private JButton SubmitButton = addButton ("Submit Answer" ,1,9/8,1,1);
  416. int generator1 = generator.nextInt(9)+1;
  417. int generator2 = generator.nextInt(9)+1;
  418. int counter = generator.nextInt(4)+1;
  419.  
  420.  
  421. int answer = generator1+generator2;
  422. JLabel questionLabel = addLabel(generator1 + "+" + generator2 + "=" ,1,30/23,20,20);
  423.  
  424.  
  425.  
  426. JTextField answerField = addTextField("" ,3/2,2,1,1);
  427.  
  428.  
  429.  
  430. }
  431.  
  432. }

the errorers are at:
class Math4 extends GBFrame{

public void additionClicked()
{
Random generator = new Random();


private JButton SubmitButton = addButton ("Submit Answer" ,1,9/8,1,1);
int generator1 = generator.nextInt(9)+1;
int generator2 = generator.nextInt(9)+1;
int answer = generator1+generator2;

JTextField answerField = addTextField("" ,3/2,2,1,1);

JLabel questionLabel = addLabel(generator1 + "+" + generator2 +"=" ,1,30/23,20,20);

if (answer == 1)
{

}
}


Note: I know the code is not formatted well, with spaces and tabs. Sorry, it is no my code it is a student who I am helping.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,568
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 196
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: Identifier expected and Illegal start of Expression errors

 
0
  #2
Jan 14th, 2009
If you expect a solution, please post the exact error code you are getting. It usually includes line numbers and method names, etc.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: Identifier expected and Illegal start of Expression errors

 
0
  #3
Jan 14th, 2009
Originally Posted by christiangirl
Note: I know the code is not formatted well, with spaces and tabs. Sorry, it is no my code it is a student who I am helping.
Use an advanced IDE like Eclipse or Netbeans, they have features like autoformat using which you can automatically format any code, no matter how badly it is written.

And just as BestJewSinceJC said, paste the exact error (without editing it) the compiler is throwing up.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 823
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

Re: Identifier expected and Illegal start of Expression errors

 
0
  #4
Jan 14th, 2009
The helper himself needs help ? Better tell the student to look at other places for solution I guess that way he would reach the solution faster. Why follow a bigger loop of he asking you and you asking us, that way he won't be able to understand how one got to the solution ain't it true ?
Last edited by verruckt24; Jan 14th, 2009 at 3:04 am.
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 108
Reputation: christiangirl is an unknown quantity at this point 
Solved Threads: 1
christiangirl christiangirl is offline Offline
Junior Poster

Re: Identifier expected and Illegal start of Expression errors

 
0
  #5
Jan 14th, 2009
I am tutoring him, and ya sometimes I need help. And I will make sure he understnds the solution.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: Identifier expected and Illegal start of Expression errors

 
0
  #6
Jan 14th, 2009
Originally Posted by christiangirl View Post
I am tutoring him, and ya sometimes I need help. And I will make sure he understnds the solution.

But how about you understanding us and pasting the exact compiler error and helping us help you help him ???
Last edited by stephen84s; Jan 14th, 2009 at 3:56 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 108
Reputation: christiangirl is an unknown quantity at this point 
Solved Threads: 1
christiangirl christiangirl is offline Offline
Junior Poster

Re: Identifier expected and Illegal start of Expression errors

 
0
  #7
Jan 14th, 2009
And heres the errors:
File: F:\Math.java [line: 384]
Error: F:\Math.java:384: illegal start of type
File: F:\Math.java [line: 384]
Error: F:\Math.java:384: <identifier> expected
File: F:\Math.java [line: 384]
Error: F:\Math.java:384: ';' expected
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 108
Reputation: christiangirl is an unknown quantity at this point 
Solved Threads: 1
christiangirl christiangirl is offline Offline
Junior Poster

Re: Identifier expected and Illegal start of Expression errors

 
0
  #8
Jan 14th, 2009
Sorry it took me longer to post the errors, I didnt see that someone else had replied.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: Identifier expected and Illegal start of Expression errors

 
0
  #9
Jan 14th, 2009
  1. private JButton SubmitButton = addButton ("Submit Answer" ,1,9/8,1,1);

I think this is the problem, I do not see any addButton() function in your class Math4, which returns an object of type JButton.

I suggest both you and your student to go through this tutorial to get your concepts on creating GUI with swing right.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,609
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 464
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Identifier expected and Illegal start of Expression errors

 
1
  #10
Jan 14th, 2009
> int generator1 = generator.nextInt(20)+1/2;

Operator precedence anyone?

> /*
> * To change this template, choose Tools | Templates
> * and open the template in the editor.
> */

I am surprised how someone can churn out such an unformatted code even after using an IDE / advanced text editor.

> class Math12 { /* */ }
> class Math5 { /* */ }
> class Math7 { /* */ }

The very fact that multiple classes are created which do the same thing is a clear indication of design problems with the application. Consider customizing the class instance by having constructors/factory methods.

...and many other things.

If your friend really wants to learn, tell him to start some serious reading. A lot of beginner resources are mentioned in the sticky; starting with the Java beginner tutorials ain't that bad an idea.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC