Project: Classroom Grade Analyzer - "illegal start of expression"


#1

Hi everyone,

I'm having issues trying to figure out this error message and its solution. (I feel like there may be more errors with my code aside the error stated, but I guess I would like to solve this error message first)

Here is my code:

import java.util.ArrayList;
//Class
public class GradeAnalyzer {
//Constructor
public GradeAnalyzer() {}
//Method
public int getAverage(ArrayList grades) {

if (grades.size() < 1) {
  System.out.println("Error! there are no grades.");
  return 0;
}
else {
  int sum = 0;
  for (Integer grade : grades) {
    System.out.println(grade);
    sum = sum + grade;
  }
  int average = sum / grades.size();
  System.out.println(average);
  return average;
}

public static void main(String[] args) {

  ArrayList<Integer> myClassroom = new ArrayList<Integer>();
  myClassroom.add(98);
  myClassroom.add(92);
  myClassroom.add(88);
  myClassroom.add(75);
  myClassroom.add(61);
  myClassroom.add(89);
  myClassroom.add(95);

  GradeAnalyzer myAnalyzer = new GradeAnalyzer();
  myAnalyzer.getAverage(myClassroom);
}

}

And here is my error message:

GradeAnalyzer.java:24: error: illegal start of expression
public static void main(String[] args) {
^
GradeAnalyzer.java:24: error: illegal start of expression
public static void main(String[] args) {
^
GradeAnalyzer.java:24: error: ';' expected
public static void main(String[] args) {
^
GradeAnalyzer.java:24: error: '.class' expected
public static void main(String[] args) {
^
GradeAnalyzer.java:24: error: ';' expected
public static void main(String[] args) {
^
GradeAnalyzer.java:38: error: reached end of file while parsing
}
^
6 errors

Any help will be greatly appreciated!

Thanks.


#2

use a generic Integer arraylist in the method below

public int getAverage(ArrayList grades)


#3

you need one more closing brace at the end of this block of code


#4

Thanks for that, changed to: public int getAverage(ArrayList grades) {

This was the biggest (smallest) mistake out of the whole thing lol. It worked perfectly after adding that extra curly brace.

Thanks guys!