Java Reference
In-Depth Information
Self-Test Exercises (continued)
25. Write a method definition for a method with the following heading. The
method is to be added to the class GradeBook in Display 6.18.
/**
Changes the grade for student number studentNumber
on quiz number quizNumber to newGrade.
*/
public void changeGrade( int studentNumber,
int quizNumber, int newGrade))
26. Write a method definition for a method with the following heading. The
method is to be added to the class GradeBook in Display 6.18.
/**
Returns an array with the average quiz score for each student.
*/
public double [] getStudentAverages()
27. Write a method definition for a method with the following heading. The
method is to be added to the class GradeBook in Display 6.18.
/**
Returns an array with the average score for each quiz.
*/
public double [] getQuizAverages()
Chapter Summary
An array can be used to store and manipulate a collection of data that is all of the
same type.
The indexed variables of an array can be used just like any other variables of the
base type of the array.
Arrays are objects that are created with new just like the class objects we dis-
cussed before this chapter (although there is a slight difference in the syntax
used).
A for loop is a good way to step through the elements of an array and perform
some program action on each indexed variable.
The most common programming error made when using arrays is to attempt to
access a nonexistent array index. Always check the first and last iterations of a loop
that manipulates an array to make sure it does not use an index that is illegally
small or illegally large.
Search WWH ::




Custom Search