Problem with grade analyzer: error: <identifier> expected


Hello, I have a problem with my code, it says: error: expected public static int getAverage(grades){
I tried to add an identifier to public static int getAverage(grades) but when I add it even more errors show up.
I have no idea what’s wrong, please help me.

import java.util.ArrayList;
//program calculates avarage of the grades
public class GradeAnalyzer{

public GradeAnalyzer(){

public static int getAverage(grades){
ArrayList<Integer> grades = new ArrayList<Integer>();
if (grades.size() < 1) {
	System.out.println("ArrayList is empty");
	return 0;
	int sum = 0;
  for (int grade: grades){
  sum = sum + grade;
  int average = (sum / grades.size());
  return average;


public static void main (String[] args){
ArrayList<Integer> myClassroom = new ArrayList<Integer>();    
GradeAnalyzer myAnalyzer = new GradeAnalyzer(myClassroom);
myAnalyzer.getAverage(ArrayList<Integer> myClassroom);




java is strongly types, so parameters should always state what data type they are, so dataType parameter. grades is your parameter.


I’ve already found a solution, just changed to new GradeAnalyzer();


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.