Problem with grade analyzer: error: <identifier> expected


#1

Hello, I have a problem with my code, it says:
GradeAnalyzer.java:8: 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;
	}
	else{
	int sum = 0;
  for (int grade: grades){
  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);
GradeAnalyzer myAnalyzer = new GradeAnalyzer(myClassroom);
myAnalyzer.getAverage(ArrayList<Integer> myClassroom);

}

}

#2

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


#3

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


#4

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