Identifier error in Grade Analyzer Code


#1


Hello all, Im stuck on the Grade Analyzer exercise for Java..

The only error displayed is "GradeAnalyzer.java:7: error: invalid method declaration; return type required
public getAverage(int grades){
^ "

My code is as follows: ////Start Code////

import java.util.ArrayList;

class GradeAnalyzer{

public GradeAnalyzer(){

}
public getAverage(int grades){
ArrayList grades = new
ArrayList();
if (grades.size() < 1) {
System.out.println("Error: No grades available");
return 0;
}else{
int sum = 0;
for(integer grade : grades){
sum = sum + grade;
}
}

		int average = sum/(grades.size());
		System.out.println(average);
  return (average);

}
public static void main(String[] args){
ArrayList myClassroom = new
ArrayList();
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);

}
}
////End Code///

`


#2

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