The idea is to add students to an arraylist, work out the number of students who have passed, and return that number.
I think I’m nearly there, as the code works, but it always returns the same value for the amount in the array list – and obviously, that is incorrect.
I have been doing this for hours now, and I can’t see what the missing statement within the if statement is to finish it off! I would be soo grateful for this!
import java.util.ArrayList;
class Course
{
private ArrayList<Student> people = new ArrayList<Student>();
//Add a students mark
public void add( Student s )
{
people.add(s);
}
//Return the number of students who passed (mark>= 40)
public int pass()
{
int size = people.size();
int i = 0;
int result = 0;
for (i = 0; i < size; i++)
{
Student s = people.get(i);
if(s.getMark() >= 40);
{
// what's here?
}
return result;
}
}
}
Remove this statement inside pass method
Because of this statement, when pass method is called, your local variable hides instance variable.