Below is a method that takes in studentarray and the topStudentIndexof a value calculated by another method previous.
I have multiple objects in my array. However, the for loop only managed to loop through once, and it returned the first value straight away.
I have no clue why the for loop stopped even though my st.lengthis more than
public static int computeNextHighestOverallStudentIndex(Student[] st, int topStudentIndex) {
double nextHighestOverall= 0;
int nextHighestStudentIndex = 0;
for (int i = 0; i < st.length; i++) {
if ((st[i] != null) && (!(i == topStudentIndex))){
double studentOverall = st[nextHighestStudentIndex ].getOverall();
if (studentOverall > nextHighestOverall) {
nextHighestOverall= studentOverall;
nextHighestStudentIndex = i;
}
}
}
return nextHighestStudentIndex ;
}