Java Reference
In-Depth Information
49
// 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;
}
}
50
51
52
53
54
55
56
57
58
59
60
61
return lowGrade;
62
}
63
64
// find maximum grade
65
public int getMaximum()
66
{
67
// assume first element of grades array is largest
68
int highGrade = grades[ 0 ][ 0 ];
69
70
// loop through rows of grades array
71
for ( int [] studentGrades : grades)
72
{
73
// loop through columns of current row
74
for ( int grade : studentGrades)
75
{
76
// if grade greater than highGrade, assign it to highGrade
77
if (grade > highGrade)
78
highGrade = grade;
79
}
80
}
81
82
return highGrade;
83
}
84
85
// determine average grade for particular set of grades
public double getAverage( int [] setOfGrades)
{
int total = 0 ;
// sum grades for one student
for ( int grade : setOfGrades)
total += grade;
// return average of grades
return ( double ) total / setOfGrades.length;
}
86
87
88
89
90
91
92
93
94
95
96
97
98 // output bar chart displaying overall grade distribution
99 public void outputBarChart()
100 {
Fig. 7.18 | GradeBook class using a two-dimensional array to store grades. (Part 2 of 4.)
Search WWH ::




Custom Search