Wednesday, November 5, 2014

array averages please help
































































How can I find the overall averages of the columns in this array?































































when i run my code it gives me an output that looks like this (showing me wrong averages):
































































0 1 2 3 overall grade































































Badger,Bradley 37 70 51 48 68.66666666666667































































Emu,Emma 35 81 75 40 72.83333333333334































































Aardvark,Alice 42 85 22 0 65.11111111111111































































Dodo,Donald exc 12 25 0 54.17391304347826































































Cassowary,Cassie 50 97 72 68 62.758620689655174
































































my code is :
































































































Java Code:






































































public static double[] computeAllGrades(int[][] scoreTable, int[] itemPointValues)
{

{
double totalPoints = 0;
double totalPointsPossible = 0;
double allGrades[];
double grade =0;

allGrades= new double[scoreTable.length];
int k = 0;

for(int j = 0 ; j < scoreTable.length ; j++)
{
for(int i = 0 ; i < scoreTable[0].length ; i++)
{
if(scoreTable[j][i] == -1)
{
totalPoints = totalPoints + 0;
totalPointsPossible = totalPointsPossible + 0;

}
else
{
totalPoints = totalPoints + scoreTable[j][i];
totalPointsPossible = totalPointsPossible + itemPointValues[i];
}
grade = (totalPoints/totalPointsPossible)*100;

}

allGrades[k] = grade;
k++;
}


return allGrades;}}



































































































































No comments:

Post a Comment