I need to find the deviation of multiple homework values. In order to do this, i need to store a variable homework, that is in a for loop, so it deletes itself every time it executes. Also, the number of variables i need in order to store the seperate homework score values is unknown, so i can't just make a list of variables. I think what i need to do is do a list of arrays, but im not sure if im doing it right.
here is the code of the method that includes the array i have created...
public double computeHomeworkDeviation(int homework){
int[] homeworkScore = new int[totalStudents];
if(computeHomeworkDeviationCounter < totalStudents){
homeworkScore[computeHomeworkDeviationCounter] = homework;
computeHomeworkDeviationCounter++;
}
else{
for(int k = 1; k <= totalStudents; k++){
top += Math.pow(homeworkScore[totalStudents - k] - homeworkAverage, 2);
}
homeworkDeviation = Math.sqrt(top / totalStudents);
}
return homeworkDeviation;
}
this method is called to a for loop and calls the argument of the homework variable that needs to be stored in an array list. What i have isn't working, what am i doing wrong? (i don't believe the array values are even being stored)
edit: I now split it into 2 methods.
setArrayMethod...
public void setHomeworkArray(int homework){
homeworkScore[l] = homework;
l++;
}
computeHomeworkDeviationMethod...
public double computeHomeworkDeviation(int homework){
for(int k = 1; k <= totalStudents; k++){
top += Math.pow(homeworkScore[totalStudents - k] - homeworkAverage, 2);
}
homeworkDeviation = Math.sqrt(top / totalStudents);
return homeworkDeviation;
}
am getting ArrayOutOfBoundsException error still.
What i have isn't working,Not working in which sense. error? wrong output? whatint[] homeworkScore = new int[totalStudents];outside the functioncomputeHomeworkDeviationCounterdeclared?