Post date: Apr 03, 2020 4:55:21 AM
Defining Classes 1
4.1 Class Definitions
Recommended Self-Test Exercises:
p 218: Ex. 3.
p 220: Ex. 4.
p 228: Ex. 5-9.
In-class Exercises:
Implement the following class:
the instance variable grades is a one dimensional array declared without specifying its size
the method displayInformation() displays the 1/ id, 2/ name, 3/ list of grades, and 4/ the average of the grades.
the method calculateAverage() returns the average of all the grades in the array
Implement a Student class with the following fields and methods:
the method getName() returns the name of the student
the method getAverage() returns the total score divided by the number of quizzes only if the number of quizzes in not equal to zero.
the method getTotalScore() returns the total score
the method printStudent() displays the 1/ name, 2/ total score, 3/ number of quizzes, and 4/ the average of the student.
Implement the following class:
the method showInformation() displays 1/ the radius, 2/ the color, 3/ the area, and 4/ the circumference
the method getRadius() returns the radius of the circle
the method getArea() returns the area of the circle. The area of a circle is the π x radius x radius
the method getCircumference() returns the circumference of the circle. The circumference is π x radius x 2
Implement the following class:
the method setLength(double) takes double value and saves it in the instance variable length
the method getLength() returns the length of the rectangle
the method getArea() returns the area of the rectangle. The area of a rectangle is the length x width.
the method getPerimeter() returns the perimeter of the rectangle. The perimeter is the 2 x (length + width)