i’m trying to display the average mark of students, but it’s display the wrong number, this is what i’ve tried. Any help would be greatly appreciated.
import java.util.ArrayList;
class Course
{
private ArrayList<Student> people = new ArrayList<Student>();
// return the average mark in the course
public double average()
{
double average = 0.0;
int i = 0;
for (i = 1; i < people.size(); i++)
{
int tmark = people.get(i).getMark() ;
{
average = tmark / i;
}
}
return average;
}
}
sure, you are not calculating average.. you have to divide by the size after summing all the values: