Classroom gradeanalyzer

Hi, again. I cannot find out what is wrong in my code. Can anyone help me?

import java.util.ArrayList;

public class GradeAnalyzer {

public GradeAnalyzer(){
  
}


public int getAverage(ArrayList <Integer> grades) {

if (grades.size() < 1) {
  
System.out.println("The list is empty");
return 0;
 
}
else {
int sum = 0;
  
   for(Integer s : grades){
  	 sum = sum + s;
   }
 int average = sum/grades.size;
 System.out.println(average); 
 return average;
}    
  
}
  
public static void main (String [] args) {

ArrayList<Integers> 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);  
}

}

Hello @zyndria, could you please also post the error code
that you’re getting please? Oh, & also if you go to
http://discuss.codecademy.com/t/posting-code-in-the-forums/16376
That will break it down for you on how to correctly post code in Codecademy forums.

You may need to make size a function, size().

BTW - is this an outside project? If so, please post in Corner Bar and tag it with “Java”.

1 Like

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