Hello,
I am getting Identifier expected and Illegal start of Expression erros in this code:
//"Math is our Game" - A math testing program for First through Fourth grade students
//Import GUI packages
import javax.swing.*;
import BreezySwing.*;
import java.awt.*;
import java.util.Random;
//import TurtleGraphics.*;
public class Math extends GBFrame
{
//declare variables for the window objects
private JLabel greetingLabel;
private JLabel additionLabel;
private JLabel subtractionLabel;
private JLabel multiplicationLabel;
private JLabel divisionLabel;
private JLabel randomLabel;
private JLabel grade1Label;
private JLabel grade2Label;
private JLabel inputLabel;
private JLabel gradeLabel;
private JLabel questionLabel;
private JTextField greetingField;
private JTextField additionField;
private JTextField subtractionField;
private JTextField multiplicationField;
private JTextField divisionField;
private JTextField randomField;
private JTextField grade1Field;
private JTextField grade2Field;
private JTextField inputField;
private JTextField questionField;
private JButton greetingButton;
private JButton additionButton;
private JButton subtractionButton;
private JButton multiplicationButton;
private JButton divisionButton;
private JButton randomButton;
private JButton grade1Button;
private JButton grade2Button;
private JButton grade3Button;
private JButton grade4Button;
private JButton inputButton;
private JButton quitButton;
private JButton questionButton;
/*int generator1=0;
int generator2=0;
int generator3=0;
int generator4=0;*/
JTextArea greetingArea;
Random generator = new Random(5);
//constructor
public Math()
{
setUp();
}
//Open greeting screen with welcome and Start button
public void setUp()
{
greetingLabel = addLabel("Greeting", 1, 1, 1, 1);//greetingLabel.setText("Greeting"); //= addLabel ("Greeting" ,1,1,1,1);
greetingArea = addTextArea("Welcome to Math is our Game, \na math skills program by \nNine Fingers and Ten Toes Software, Inc.", 2, 3, 3, 3);
greetingButton = addButton ("Start" ,1,3,1,1);
}
//Button clicked to start game
public void buttonClicked(JButton buttonObj)
{
this.setVisible(false);
math3 test = new math3();
test.setVisible(true);
test.setSize(500, 500);
//First grade selected
//public void buttonClicked (JButton button)
//{
if (buttonObj == grade1Button)
{
JOptionPane.showMessageDialog(null, "Hi");
//Generate numbers for First Grade problem
int generator1 = generator.nextInt(5);
int generator2 = generator.nextInt(5);
//Select type of problem
//instantiates and add window objects to the window
}
//public void buttonClicked (JButton buttonObj)
//{
//local variables
Math2 math1 = new Math2();
//determine which button was clicked
if (buttonObj == grade2Button)
{
//setting and getting the numbers for the equations
math1.setaddition(Double.parseDouble(additionField.getText()));
//subtractionField.setNumber(math1.getsubtraction());
//math1.setmultiplication(Double.parseDouble(multiplicationField.getText()));
//divisionField.setNumber (math1.getdivision());
//math1.setrandom(randomField.getText());
}
}
class math3 extends GBFrame
{
//Select grade level - Instantiate and add window objects to grade level window
JLabel gradeLabel = addLabel("Please select grade level of math problem.", 1, 1, 1, 1);// ,1,1,1,1);
JButton grade1Button = addButton ("First Grade" ,1,1,1,1);
JButton grade2Button = addButton ("Second Grade" ,2, 1,1,1);
JButton grade3Button = addButton ("Third Grade" ,3,1,1,1);
JButton grade4Button = addButton ("Fourth Grade" ,4,1,1,1);
JButton quitButton = addButton ("Quit" ,5,1,1,1);
JButton gobackButton = addButton ("Revert Back" ,6,1,1,1);
public void buttonClicked(JButton buttonObj)
{
if (buttonObj == quitButton)
System.exit(0);
if (buttonObj == gobackButton)
{
//Select grade level - Instantiate and add window objects to grade level window
math3 s = new math3();
gobackButton = addButton ("Revert Back" ,6,1,1,1);
}
if (buttonObj == grade1Button)
{
addButtons P = new addButtons();
this.setVisible(false);
P.setVisible(true);
P.setSize(700, 700);
}
}
}
public static void main(String [] args)
{
Frame frm = new Math();
frm.setSize(500,500);
frm.setVisible(true);
}
class Math2
{
private double Mathsubtraction;
public void setaddition(double math)
{
Mathsubtraction = math;
}
public double setsubtraction(double math)
{
return Mathsubtraction;
}
public double getsubtraction()
{
return Mathsubtraction;
}
public double getaddition()
{
double Mathaddition = 0;
return Mathaddition;
}
String getdivision() {
throw new UnsupportedOperationException("Not yet implemented");
}
void setdivision(double parseDouble) {
throw new UnsupportedOperationException("Not yet implemented");
}
void setmultiplication(double parseDouble) {
throw new UnsupportedOperationException("Not yet implemented");
}
void setrandom(double parseDouble) {
throw new UnsupportedOperationException("Not yet implemented");
}
void getrandom() {
throw new UnsupportedOperationException("Not yet implemented");
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Tyler
*/
class math2 {
void setaddition(double parseDouble) {
throw new UnsupportedOperationException("Not yet implemented");
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author TBoden
*/
class addButtons extends GBFrame
{
JLabel additionLabel = addLabel ("Addition" ,1,2,1,1);
JLabel subtractionLabel = addLabel ("Subtraction" ,1,3,1,1);
JLabel multiplicationLabel = addLabel ("Multiplication" ,1,4,1,1);
JLabel divisionLabel = addLabel ("Division" ,1,5,1,1);
JLabel randomLabel = addLabel ("Random" ,1,6,1,1);
JLabel gobackLabel = addLabel ("Revert Back" ,1,7,1,1);
JTextField additionField = new JTextField("0");
JTextField subtractionField = new JTextField("0");
JTextField multiplicationField = new JTextField("0");
JTextField divisionField = new JTextField("0");
JTextField randomField = new JTextField("0");
JTextField gobackField = new JTextField("0");
JButton additionButton = addButton ("1+1" ,1,5/3,1,1);
JButton subtractionButton = addButton ("1-1" ,4,1,1,1);
JButton multiplicationButton = addButton ("1*1" ,5,1,1,1);
JButton divisionButton = addButton ("1/1" ,6,1,1,1);
JButton randomButton = addButton ("Random Equation" ,7,1,1,1);
JButton gobackButton = addButton ("Revert Back" ,8,1,1,1);
public void buttonClicked(JButton buttonObj)
{
if (buttonObj == additionButton)
{
Math4 m = new Math4();
this.setVisible(false);
m.setVisible(true);
m.setSize(700, 700);
}
if (buttonObj == subtractionButton)
{
Math5 m = new Math5();
this.setVisible(false);
m.setVisible(true);
m.setSize(700, 700);
}
if (buttonObj == multiplicationButton)
{
Math6 m = new Math6();
this.setVisible(false);
m.setVisible(true);
m.setSize(700, 700);
}
if (buttonObj == divisionButton)
{
Math12 m = new Math12();
this.setVisible(false);
m.setVisible(true);
m.setSize(700, 700);
}
if (buttonObj == randomButton)
{
Math7 m = new Math7();
this.setVisible(false);
m.setVisible(true);
m.setSize(700, 700);
}
}
class Math12 extends GBFrame{
Random generator = new Random();
private JButton SubmitButton = addButton ("Submit Answer" ,1,9/8,1,1);
int generator1 = generator.nextInt(20)+1/2;
int generator2 = generator.nextInt(20)+1/2;
int answer = generator1/generator2;
JTextField answerField = addTextField("" ,3/2,2,1,1);
JLabel questionLabel = addLabel(generator1 + "/" + generator2 + "=" ,1,30/23,20,20);
}
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)
{
}
}
}
class Math6 extends GBFrame{
Random generator = new Random();
private JButton SubmitButton = addButton ("Submit Answer" ,1,9/8,1,1);
int generator1 = generator.nextInt(5)+1;
int generator2 = generator.nextInt(5)+1;
int answer = generator1*generator2;
JTextField answerField = addTextField("" ,3/2,2,1,1);
JLabel questionLabel = addLabel(generator1 + "*" + generator2 + "=" ,1,30/23,20,20);
}
class Math5 extends GBFrame{
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);
}
class Math7 extends GBFrame{
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 counter = generator.nextInt(4)+1;
int answer = generator1+generator2;
JLabel questionLabel = addLabel(generator1 + "+" + generator2 + "=" ,1,30/23,20,20);
JTextField answerField = addTextField("" ,3/2,2,1,1);
}
}
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.