Classroom Grades Analyzer


#1
import java.util.ArrayList;

public class GradeAnalyzer{
  
  public GradeAnalyzer(){
    
  }
  
  public int getAverage(){
    
    ArrayList<Integer> grades = new ArrayList<Integer>();
    
    if (grades.size() < 1){
      
      System.out.println("Error. Not empty");
      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<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);
    
    
  }
  
}

GradeAnalyzer.java:48: error: method getAverage in class GradeAnalyzer cannot be applied to given types;
myAnalyzer.getAverage(myClassroom);
^
required: no arguments
found: ArrayList
reason: actual and formal argument lists differ in length
1 error

I do not know what to do.
I found a discussion on this topic. But for those links I could not fix anything.


#2

your getAverage method:

public int getAverage()

has no parameters, so how can it take argument (myClassroom) at method call?


#3

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