Compiler errors with arrays

Can someone please tellme why my program will not compile. What I am trying to do is make a program that accepts a number of scores then computes the scores to output an average. I also want it to output each array element on a seperate line at the end.

public class Tests

{

   public static void main(String[] args)

    {
             /*Variables*/

             int numberOfTests = 0;
             double averageScore = 0;
             private TestTaker[] record;
             int sum = 0;

             public void getTests()

             {

             /*Description of program for user.*/

             System.out.println("This program will calculate your average");
             System.out.println("for a certain number of test scores that you enter.\n");
             System.out.println("How many test scores will you be entering?");

             numberOfTests = readInput();

             test = new TestTaker[numberOfTests];
             int i;
             for (i=0; i<numberOfTests;i++)

             {
                  test[i] = new TestTaker();
                  System.out.println("Enter the score for test number " + (i+1));
                  test[i].readInput();
                  System.out.println();
             }

            }

            /*Computes the average test scores*/

            public void computation()
            {

                  int i;
                  double nextTest = test[0].getTests();
                  double sum = nextTest;
                  for (i=1; i < numberOfTests; i++)

                  {
                        nextTest = test[i].getTests();
                        sum = sum + nextTest;
                  }

                  averageScore = sum/numberOfTests;

                  System.out.println("The average test score for all tests entered is " + averageScore);

            };


}

}
nikeseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
You need a class called 'TestTaker' for one thing. I would make your main class, 'Tests' responsible for reading input. Assign the scores to TestTaker
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nikeseAuthor Commented:
Is there a way to do it without a different class? Like writing in some line that accepts input? I am wanting to make it all in one class.
0
CEHJCommented:
>>Is there a way to do it without a different class?

Yes, you can do it all in one class, but you've already specified another class:

>>private TestTaker[] record;
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

CEHJCommented:
You need to make that something like:

int[] testScores = new int[numberOfTests];
0
CEHJCommented:
You don't actually even need an array - you can just calculate a running total:

total += readInput();
0
nikeseAuthor Commented:
ooops, I am reading a book and having a hard time understading this. I guess I could just take that out then if I don't actually have another class already. Right? In doing so, I still get an error on public void getTests (). Once I get past these and find a line that accepts input, then I can tell if the rest of what I have done works.
0
CEHJCommented:
Or rather

sum += readInput();
0
nikeseAuthor Commented:
Unfortunately, I am trying to learn arrays so I am making myself use them in this program.

Once I substituted the above line, I still get an error on public void getTests(). Do I even need this line?
0
nikeseAuthor Commented:
Well, I guess I do because when I take it out I get a million other errors. I am stuck.
0
objectsCommented:
try the following:

import java.io.*;

public class Tests

{

   public static void main(String[] args) throws IOException

    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
       
           /*Variables*/

           int numberOfTests = 0;
           double averageScore = 0;
           int[] test;

           /*Description of program for user.*/

           System.out.println("This program will calculate your average");
           System.out.println("for a certain number of test scores that you enter.\n");
           System.out.println("How many test scores will you be entering?");

           numberOfTests = Integer.parseInt(in.readLine());

           test = new int[numberOfTests];
           for (int i=0; i<numberOfTests;i++)

           {
               System.out.println("Enter the score for test number " + (i+1));
               test[i] = Integer.parseInt(in.readLine());
               System.out.println();
           }

         /*Computes the average test scores*/

                double sum = 0;
               for (int i=0; i < numberOfTests; i++)

               {
                    sum = sum + test[i];
               }

               averageScore = sum/(double)numberOfTests;

               System.out.println("The average test score for all tests entered is " + averageScore);

}

}
0
CEHJCommented:
You should begin by commenting out nearly everything. Start with main. Don't have other methods nesting inside it. In main, create an instance of Tests, then work on the constructor of Tests
0
nikeseAuthor Commented:
I will try these ideas and get back with you guys in about a half an hour. I will let you know.
0
RuadRauFlessaCommented:
Check the code that objects dished out. It should work correctly. except for the fact that you would like to print out the results of the diffirent test at the end as well. For that you can simply change the following:


  /*Computes the average test scores*/

  double sum = 0;
  for (int i=0; i < numberOfTests; i++)
  {
    System.out.println("test[" + i + "] = " + test[i]);
    sum = sum + test[i];
  }

  then you should have your output sorted.

One more thing I don't know what you planned on doing with the [code]public void computation()[/code] method but if you were planning on calling it from the [code]public static void main(String[] args)[/code] method then you would have to declare it as being static. ([code]public static void computation()[/code])
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.