Download as pdf or txt
Download as pdf or txt
You are on page 1of 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