Grade Analyzer Help. Stuck at the end


#1



https://www.codecademy.com/courses/learn-java/projects/grades-analyzer

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>();
        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);
    }

}


#2

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


#3

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.


#4

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