Why no output here
Here's some simple code I'm working on but I can't get the mean to display. Everything compiles correctly but the "Mean will not display. What did I do wrong?
// Two-dimensional array to store grade data.
publicclass Gradebook
{
privateint grades[][];// two-dimensional array of student grades
//constructor initializes grades array
public Gradebook( String name,int gradesArray[][] )
{
grades = gradesArray;// store grades
}// end GradeBook constructor
// perform various operations on the data
publicvoid processGrades()
{
// output grades array
// call methods getMinimun, getMaximum, getMean, getMode
System.out.printf("\n%s %d\n%s %d\n\n",
"Lowest grade is", getMinimum(),
"Highest grade is", getMaximum(), getMean());
}
// end method processGrades
// find minimum grade
publicint getMinimum()
{
// assume first element of grades array is smallest
int lowGrade = grades[ 0 ][ 0 ];
// loop through rows of grades array
for (int studentGrades[] : grades )
{
// loop through columns of current row
for (int grade : studentGrades )
{
// if grade less than lowGrade, assign it to lowGrade
if ( grade < lowGrade )
lowGrade = grade;
}// end inner for
}// end outer for
return lowGrade;// return lowest grade
}// end method getMinimum
// find maximum grade
publicint getMaximum()
{
// assume first element of grades array is largest
int highGrade = grades[ 0 ][ 0 ];
// loop through rows of grades array
for (int studentGrades[] : grades )
{
// loop through columns of current row
for (int grade : studentGrades )
{
// if grade greater than highGrade, assign it to highGrade
if ( grade > highGrade )
highGrade = grade;
}// end inner for
}// end outer for
return highGrade;// return highest grade
}// end method getMaximum
// find Mean
publicdouble getMean ()
{
int rows =0;
int cols =0;
int i, j, num;
double mean, total = 0.0;
// Find the sum of all the elements
for (i = 0; i < rows; i++)
{
for (j = 0; j < cols; j++)
{
total += grades[i][j];
}
}
// Calculate number of elements
num = rows * cols;
// Find the mean
mean = total/num;
System.out.printf("The Mean is", + mean);
return mean;
}
}// end class GradeBook
The "test code" is here:
/// Creates GradeBook object using an array of grades.
publicclass GradebookTest
{
// main method begins program execution
publicstaticvoid main( String args[] )
{
// two- dimensional array of student grades
int gradesArray[] [] ={{88,99,89,88,77},// Student 1
{98,75,66,89,65},//Studen 2
{90,89,70,78,100},//Student 3
{94,74,86,89,63},//Student 4
{99,76,99,89,64},// Student 5
{89,76,89,88,56},// Student 6
{98,76,89,88,99},//Student 7
{98,89,66,88,89}};//Student 8
Gradebook myGradebook =new Gradebook
("", gradesArray);
// myGradebook.displayMessage();
myGradebook.processGrades();
}// end main
}// end class GradeBookTest

