Grade Analyzer - Issue


#1

HI everyone! I’m struggling a bit as I complete this project (or may have a long way to go). I’ve been able to solve most on my own, but after spending two days resolving another wall I was hitting, I’m ready to ask for a little help. Thanks in advance!

The error message I’m getting:

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

My code:

import java.util.ArrayList;

class GradeAnalyzer {
  
  public GradeAnalyzer() {
    
    
  }
  
  public static int getAverage() {
    
 		ArrayList<Integer> grades = new ArrayList<Integer>();
    
    if(grades.size() < 1) {
        
      System.out.println("Friendly message");
      System.out.println(0);
      
    }else {
      
      int sum;
      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(75);
    myClassroom.add(61);
    myClassroom.add(89);
    myClassroom.add(95);
    
    GradeAnalyzer myAnalyzer = new GradeAnalyzer();
    myAnalyzer.getAverage(myClassroom);
    
    
  }
  
}

#2

look at getAverage:

public static int getAverage()

it has no parameters, so no arguments are required. Yet when you call the method:

myAnalyzer.getAverage(myClassroom);

yet when you call the method, you provide an argument. This mismatch between argument(s) and parameter(s) is what is causing the error


#3

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