0% found this document useful (0 votes)
41 views3 pages

Week3-CS111-Lab3 - 2 - Tuesday 1 PDF

This lab focuses on practicing inheritance and is-a relationships in Java. Students will implement a UML class diagram with a superclass and subclass that uses inheritance. Specifically, students will create a Staff superclass and Faculty subclass, with the Faculty subclass inheriting from Staff using an is-a relationship. Methods like calculateSalary() will be overridden in the subclass. A test application will demonstrate the capabilities of the classes by creating objects and calling their methods.

Uploaded by

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

Week3-CS111-Lab3 - 2 - Tuesday 1 PDF

This lab focuses on practicing inheritance and is-a relationships in Java. Students will implement a UML class diagram with a superclass and subclass that uses inheritance. Specifically, students will create a Staff superclass and Faculty subclass, with the Faculty subclass inheriting from Staff using an is-a relationship. Methods like calculateSalary() will be overridden in the subclass. A test application will demonstrate the capabilities of the classes by creating objects and calling their methods.

Uploaded by

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

CS 111T - Lab

Programming Language 2
Computer Science Department
2023

Lab Objectives:
In this lab, a student will practice

• Reading part of a UML class diagram • Implementing is-a relationship.


• Creating a class. • Overriding toString method
• Declaring instance variables. • Overriding methods.
• Declaring a constructor. • Writing a test application to
• Declaring accessors and mutators demonstrate the capabilities of another
methods classes.
Lab Exercise:
Given the following UML implement all the classes in the same package with all needed instance variables,
accessor and mutators methods and constructors; then write a test application to demonstrate the classes
capabilities.

Consider the following points:


Link the class Faculty with class Staff by is_a relationship and add any needed suitable methods.
In Staff Class:
• calculateSalary() return the price by calling getBaseSalary() method.
In Faculty Class:
• Use constructor call chaining to refer superclass using the keyword super.
• Override the method calculateSalary() to return the salary which equals
(monthlyTeachingLoad+ monthlyAdminLoad)*baseSalary, use @Override annotation.
In main:
• create object of type Staff,
• create object of type Faculty
• Then call method calculateSalary() of Faculty object you created, and print the value.

Assignment:
Write a Java program that demonstrate Inheritance, “is-A” relationship. Your program must
logically represent the relationship. DO NOT use the examples from the lecture

In your program, design and implement 3 classes ( one superclass and two subclasses ) in the
same package with all needed instance variables, accessor and mutators methods and
constructors; then write a test application to demonstrate the classes capabilities.

Consider the following points:

• Declare 2 instance variables in each class


• Create full Argument constructor in each classes
• Create a getter and setter methods in each classes.
• Create a method in superclass , then Override the same method in both subclasses
• in main create an object from both subclasses
• call the (Override) method for each object

You might also like