Class Roster Program with Polymorphism
Description
This program incorporates the OOP inheritance concept to design classes to represent different types of student.The client program incorporates the OOP Polymorphism concept to process a variety of subclass objects.
Suppose a college course enrolled with both undergraduate and graduate students.
Each student, either undergraduate or graduate, has the name, three test scores, and the final course grade as data members.
The final course grade, either pass or no pass, is determined differently.
The superclass Student defines the common features that apply to any types of student.
Data members: name, tests, grade
constructors
getters and setters
determineGrade method
toString method
constructors
getters and setters
determineGrade method
toString method
The subclasses UndergraduateStudent and GraduateStudent inherit the superclass Student's features and override the determineGrade method.
Undergraduate: average test score >= 70
Graduate: average test score >=80
Graduate: average test score >=80
Associated Concepts:
OOP - Inheritance
OOP - Polymorphism
OOP - Polymorphism
Algorithm:
Class diagrams:
Client program:
Client program:
The client program creates an ArrayList of superclass Student
and adds subclass objects to the ArrayList in random order.
It then invokes the determineGrade() method in the loop using the superclass references.
It then invokes the determineGrade() method in the loop using the superclass references.
Source Code
Superclass Student classSubclass GraduateStudent class
subclass UndergraduateStudent class
Client program