COMP2247 - Algorithms and Data Structures

Syllabus Software Installation Assignments Tests
Lectures and Labs
**Back to Full Menu**

OOP - Abstract Method/Class Pet Program Payroll Program Class Roster Program



Class Roster Program with Abstract


Description

This program incorporates OOP inheritance, polymorphism, and abstract method / class concepts to design classes to represent different types of student.

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 abstract superclass Student defines the common features that apply to any types of student.

Method determineGrade() is an abstract method.

Data members: name, tests, grade

constructors

getters and setters

determineGrade method

toString method

The concrete 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

Associated Concepts:

OOP - Inheritance

OOP - Polymorphism

OOP - Abstract Method / Class

Algorithm:

Class diagrams:



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.

Source Code

Superclass Student class



Subclass GraduateStudent class



subclass UndergraduateStudent class



Client program



Sample Run



Video