Lab Sheet 6
Lab Sheet 6
Lab sheet
1. Create a class named Shape with properties name and color. Implement getters, setters,
default and parameterized constructors. And do the following tasks.
a. Create a class named Circle with property radius extended from the Shape class.
b. Create a class named Rectangle with properties length and width extended from
the Shape class.
c. Complete the Circle and Rectangle classes with getters, setters and constructors.
d. Create objects from the Circle and Rectangle classes and test the methods
implemented.
e. Add a method to calculate the area of shape in each class (Circle. Rectangle).
g. Test the implemented method using objects.
2. Create a class named MathOperations with overloaded methods for handling different data
types (integers and floats). Implement the methods to perform addition of two numbers or three
numbers based on the data types passed as arguments.
3. Create an abstract class named "Lecturer" featuring attributes such as employee ID, name, and
address. This abstract class includes an abstract method to calculate the monthly payment. Create
concrete classes, namely "PermanentLecturer" and "VisitingLecturer" which are inherited
from the abstract parent class. Each concrete class provides specific implementations for the
abstract method.
For Visiting Lecturers, introduce attributes indicating the worked hours and payment per
hour.
Monthly payment for a Visiting Lecturer is computed as the product of payment per hour
and hours worked.
Permanent Lecturers possess an attribute representing a fixed salary. The way of
calculating monthly payment for both lecturer types is given below.
4. Create an interface named "3DShape" that defines methods for calculating area and volume.
Implement this interface in classes Sphere, Cuboid and Cylinder. Each class should provide
unique implementations for area and volume calculations based on their specific geometric
properties. Refer to the table below for the equations of the shapes.
3D Shape Area Volume
Sphere (radius – r) 4Π𝑟2 3 3
Π𝑟
4
Cuboid (length – l, width – w, height - h) 2 x lw + 2 x lh + 2 x wh lxbxh
Cylinder (radius – r, height – h) 2Π𝑟2 + 2Π𝑟ℎ Π𝑟2ℎ