Grade Analyzer Help. Stuck at the end


Hello for some reason when I run the code below it gives the number of array's(?) used. Any help would be appreciated. Here's what I wrote below.

//Check class grades
import java.util.ArrayList;

//Pulic class with methods
public class GradeAnalyzer {

    public GradeAnalyzer() {


    public int getAverage(ArrayList<Integer> grades) {
        if (grades.size() < 1) {
            System.out.println("ArrayList is empty!");
            return 0;

        } else {
            int sum = 0;

            for (Integer grade : grades) {
                sum = sum + grades.size();

            int average = sum / grades.size();
            System.out.println("Average is " + average);
            return average;


//Main method with an ArrayLisy
    public static void main(String[] args) {
        ArrayList<Integer> myClassroom = new ArrayList<Integer>();

        GradeAnalyzer myAnalyzer = new GradeAnalyzer();



Have you had a look at what operations you're doing to reach that result? They're not that many.


I figured out what was wrong. In the For Each statement, I had "sum = sum + grades.size();" when it should have been "sum = sum + grade;". Thanks for the help.


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