Ok so im doing a project for school and i made an array to add up the scores. (the project is a learning module, (game)). So heres my code, i have declared everything in my main program (starting one) called science.java and my two other parts of the game (true and false and multiple choice adds up, this one doesnt. Please help. Here are the declaring codes in my main program (its global) and here is the problem.

public static JFrame Lesson0 = new JFrame ("World of Eubacteria"); //creates a frame with title
    public static JFrame Howtoplay = new JFrame ("How to Use the Program!"); //creates a frame with title
    public static JFrame Testknowledge = new JFrame ("Test Time!"); //creates a frame with title
    public static JFrame science = new JFrame ("Robbie's Learning Program - Bacteria"); //creates a frame with title
    public static JFrame Testknowledge1 = new JFrame ("Test - Multiple Choice");
    public static JFrame Lesson1 = new JFrame ("World of Eubacteria - Continued"); //creates a frame with title
    public static JFrame Lesson2 = new JFrame ("Land of Archaebacteria"); //creates a frame with title
    public static JFrame Lesson3 = new JFrame ("Land of Archaebacteria - Continued"); //creates a frame with title
    public static JFrame Testknowledge2 = new JFrame ("Test - True and False"); //creates a frame with title
    public static JFrame Testknowledge3 = new JFrame ("Test - Fill in the Blanks"); //creates a frame with title
    public static JFrame Results = new JFrame ("Test - Results"); //creates a frame with title
    public static int sum[] = new int [4];
    public static double avg[] = new double [4];
    public static int counter = 0;


        
        public static double average (int sum){
        double average = 0.0;
            average += sum;
            average/= 15;
            average*=100;
            return average;
            }
            
        public static double averagesingle (int sum){
        double averagesingle =0.0;
        averagesingle +=sum;
        averagesingle/=5;
        averagesingle*=100;
        return averagesingle;
        }






and here is my problem program part



import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.awt.Color;
import java.awt.Font;



public class Testknowledge3 extends JPanel implements ActionListener
{
    //Declare objects
    JButton Next;
    JButton Back;
    JLabel label;
    ImageIcon icon;
    JTextArea title;


    JTextArea paragraph;
    JTextArea fill1;
    JTextArea fill2;
    JTextArea fill3;
    JTextArea fill4;
    JTextArea fill5;




    public Testknowledge3 ()
    {
        super (null);

        //set up GUI
        setBackground (Color.blue);


        title = new JTextArea ("Fill In The Blanks");
        title.setFont (new Font ("Serif", Font.BOLD, 30));
        title.setForeground (Color.white);

        paragraph = new JTextArea (" Eubacteria are simple organisms that lack nuclei \n (Therefore called                      ). They can be \n heterotrophs or                      so they either create \n energy by consumption of other organisms, \n                      or chemosynthesis.  The cell wall of \n Eubacteria contain Peptidoglycan, a 3 dimensional \n polymer containing                       & protein subunits. \n There are 3 types of Archaebacteria: Thermophiles \n (Heat), Halophiles, and                      .");
        paragraph.setFont (new Font ("Serif", Font.BOLD, 20));
        paragraph.setForeground (Color.yellow);

        fill1 = new JTextArea ();
        fill2 = new JTextArea ();
        fill3 = new JTextArea ();
        fill4 = new JTextArea ();
        fill5 = new JTextArea ();



        Next = new JButton ("Next to Results!");
        Back = new JButton ("Back To Menu");




        Next.setBounds (320, 330, 150, 20);
        Back.setBounds (20, 330, 120, 20);

        title.setBounds (130, 10, 9999, 9999);
        paragraph.setBounds (30, 50, 9999, 9999);
        fill1.setBounds (190, 83, 100, 20);
        fill2.setBounds (172, 110, 100, 20);
        fill3.setBounds (30, 165, 105, 20);
        fill4.setBounds (203, 217, 100, 20);
        fill5.setBounds (238, 270, 100, 20);



        Back.addActionListener (this);
        Next.addActionListener (this);


        Next.setActionCommand ("Results");
        Back.setActionCommand ("BacktoMenu");


        add (fill5);
        add (fill4);
        add (fill3);
        add (fill2);
        add (fill1);
        add (Next);
        add (Back);
        add (paragraph);
        add (title);




        label = new JLabel (); //create a JLabel1
        label.setBounds (0, 0, 500, 400);
        icon = new ImageIcon ("greenbac.jpg");
        label.setIcon (icon); //add icon to JLabel
        add (label);

        paragraph.setEditable (false);
        paragraph.setOpaque (false);
        title.setEditable (false);
        title.setOpaque (false);


    } //end public UIProgram ()


    public void actionPerformed (ActionEvent e)
    {

        String Action;
        Action = e.getActionCommand (); //gets the setActionCommand()

        if (Action.equals ("Results"))
        {
            Results ();
            if (fill1.getText().equalsIgnoreCase ("Prokaryotic"))
            {
                science.sum [science.counter] += 1;
            }
            if (fill2.getText().equalsIgnoreCase ("Autotrophs"))
            {
                science.sum [science.counter] += 1;
            }
            if (fill3.getText().equalsIgnoreCase ("Photosynthesis"))
            {
                science.sum [science.counter] += 1;
            }
            if (fill4.getText().equalsIgnoreCase ("Peptidoglycan"))
            {
                science.sum [science.counter] += 1;
            }
            if (fill5.getText().equalsIgnoreCase ("Methanogens"))
            {
                science.sum [science.counter] = 1;
            }

            science.avg [science.counter] = science.averagesingle (science.sum [science.counter]);
            science.sum [3] += science.sum [science.counter];
            science.avg [3] += science.average (science.sum [3]);
            science.counter++;

        }
        else if (Action.equals ("BacktoMenu"))
        {
            MainMenu ();
        }
    }



    public void Results ()
    {

        science.Results.getContentPane ().add (new Results ()); //adds your Jpanel to the frame
        science.Results.setSize (new Dimension (500, 400));  // sets the dimensions of the window
        science.Results.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); //closes the program if the X(close window) is clicked
        science.Results.show (); //show the frame
        science.Testknowledge3.hide ();
    }



    public void MainMenu ()
    {

        science.science.getContentPane ().add (new science ()); //adds your Jpanel to the frame
        science.science.setSize (new Dimension (500, 400));  // sets the dimensions of the window
        science.science.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); //closes the program if the X(close window) is clicked
        science.science.show (); //show the frame
        science.Testknowledge3.hide ();


    }


    public static void main (String[] arg)
    {


        science.Testknowledge3.getContentPane ().add (new Testknowledge3 ()); //adds your Jpanel to the frame
        science.Testknowledge3.setSize (new Dimension (500, 400));  // sets the dimensions of the window
        science.Testknowledge3.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); //closes the program if the X(close window) is clicked
        science.Testknowledge3.show (); //show the frame



    }
} //end class

If you can help id love it! Thanks People!!!

Code tags please.

[code=JAVA] // paste code here

[/code]

Please repost with code tags and point to the specific lines where data should be adding up, but isn't. Thanks.

So where's the problem? (Not that I really looked at the code yet, but you said "here's the problem", but then, didn't say what the problem was.)

Also, what is "global", as there is no "global" anything in Java.

This article has been dead for over six months. Start a new discussion instead.