0% found this document useful (0 votes)
566 views1 page

Lab 6 - Inheritance and Polymorphism Answer The Following Questions

The document discusses inheritance and polymorphism in object-oriented programming with Java. It provides exercises to create class hierarchies for bank accounts, people, and geometric shapes. For bank accounts, there are subclasses for checking and savings accounts. For people, there are subclasses for students, employees, faculty, and staff. Geometric shapes have subclasses for circles and cylinders. The exercises test polymorphism and implementing interfaces.

Uploaded by

flowerpot321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
566 views1 page

Lab 6 - Inheritance and Polymorphism Answer The Following Questions

The document discusses inheritance and polymorphism in object-oriented programming with Java. It provides exercises to create class hierarchies for bank accounts, people, and geometric shapes. For bank accounts, there are subclasses for checking and savings accounts. For people, there are subclasses for students, employees, faculty, and staff. Geometric shapes have subclasses for circles and cylinders. The exercises test polymorphism and implementing interfaces.

Uploaded by

flowerpot321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Object Oriented Development with Java (CT038-3-2) Inheritance and Polymorphism

Lab 6 –Inheritance and Polymorphism


Answer the following questions.

Instructor-led Demo:

1. The Account class is to model a bank account. An account has the properties
account number, balance, and annual interest rate, and methods to deposit and
withdrawal. Create two subclasses for checking and saving accounts. A checking
account has an overdraft limit, but a savings account cannot go overdrawn. Test your
program.

Exercise:

1. Implement a class named Person and two subclasses of Person named Student
and Employee. Make Faculty and Staff subclasses of Employee. A person
has a name, address, phone number, and email address. A student has a status
(freshman, sophomore, junior, or senior). Define the status as a constant (Hint: Use
Enum). An employee has an office, salary, and date-hired. Define a class named
MyDate that contains the fields year, month, and day. A faculty member has office
hours and a rank. A staff member has a title, override the toString method in each
class to display the class name and the person’s name.
a. Furthermore from Q1, make FullTime and PartTime subclasses of
Staff. Full time staff has a fixed salary whereas part time staff has a salary
depending on worked hour. Implement this requirement that demonstrate the
earning for both staff.
b. Test your program. Demonstrate the result to the instructor.

2. Enabling GeometricObject comparable, Circle and Cylinder are subclasses


of GeometricObject. Modify the GeometricObject class to implement the
Comparable interface, define the max method in the GeometricObject class.
Write a test program that uses the max method to find the larger of two circles and the
larger of two cylinders.
a. Create a class named ComparableCylinder that extends Cylinder and
implements Comparable. Implement the compareTo method to compare
the cylinders on the basic of volume. Write a test class to find the larger of two
instances of ComparableCylinder objects.
b. Create an interface named Colorable having an abstract method named
howtoColor method. Every class of a colorable object must implement the
Colorable interface. Create a class named Square that extends
GeometricObject and implements Colorable. Implement
howToColor to display a message on how to color the square.

Level 2 Asia Pacific University of Technology and Innovation Page 1 of 1

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy