Storing Student Grades in an Array in Class GradeBook
Class GradeBook
(Fig. E.13) uses an array of int
s to store several students’ grades on a single exam. This eliminates the need to repeatedly input the same set of grades. Array grades
is declared as an instance variable (line 7), so each GradeBook
object maintains its own set of grades. The constructor (lines 10–14) has two parameters—the name of the course and an array of grades. When an application (e.g., class GradeBookTest
in Fig. E.14) creates a GradeBook
object, the application passes an existing int
array to the constructor, which assigns the array’s reference to instance variable grades
(line 13). The grades
array’s size is determined by the length of the array that’s passed to the ...
Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.