0% found this document useful (0 votes)
2 views8 pages

Esof5232 Lab04 Md. Khan

This lab report introduces key concepts of Java programming, focusing on abstract classes, inheritance, and polymorphism within a payroll system. It details the implementation of various employee classes and demonstrates how polymorphism enables uniform processing of different employee types. The output confirms that the Java program functions as intended, accurately calculating employee earnings.

Uploaded by

md.irfanemon1996
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)
2 views8 pages

Esof5232 Lab04 Md. Khan

This lab report introduces key concepts of Java programming, focusing on abstract classes, inheritance, and polymorphism within a payroll system. It details the implementation of various employee classes and demonstrates how polymorphism enables uniform processing of different employee types. The output confirms that the Java program functions as intended, accurately calculating employee earnings.

Uploaded by

md.irfanemon1996
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

Page 1 of 8

Lab 04 : Introduction to Java


ESOF- 5232
Software Construction and Evolution

Instructor: Dr. Ayman Diyab

Experiment Contacted on: 01/02/2024


Report Submitted on: 08/02/2024

Name: Md Irfanul Islam Khan


Student ID: 1242074
Email: khanm438@[Link]

Department of Electrical & Computer Engineering


Lakehead University
Thunder Bay, Ontario
Page 2 of 8

Table of Content

Topics Name Page Number


Objective 3
Introduction 3
Running a program in Java 3
Object Oriented Programming 3
Code of Assignment 04 4
Output of Assignment 7
Summary 8
Conclusion 8
Page 3 of 8

Objective:
The objective of this Lab report is to introduce Abstract Classes, Superclass/Subclasses and
Polymorphism in given Payroll System.

Introduction:
In Java, an abstract class is a class that cannot be instantiated on its own and may contain abstract
methods. An abstract method is a method that is declared but not implemented in the abstract class.
In object-oriented programming, the concepts of superclass and subclasses are part of inheritance,
a fundamental mechanism that allows one class to inherit the properties and behaviors of another
class. Polymorphism is a fundamental concept in object-oriented programming (OOP) that allows
objects of different types to be treated as objects of a common type. It enables a single interface to
represent different types of objects and allows code to be written that can work with objects of
various classes, usually through the use of inheritance and interfaces.

Running a Program in Java:

For assignment 4 :
This Java program appears to be a test program for a payroll system that involves different types
of employees. The program creates instances of various employee classes, including Salaried
EmployeeClass, HourlyEmployeeClass, CommissionEmployee, BasePlusCommissionEmployee,
and PieceWorker.
These classes seem to be part of an employee hierarchy.

Employee Classes:

SalariedEmployeeClass: Represents an employee paid a fixed salary.


HourlyEmployeeClass: Represents an employee paid by the hour.
CommissionEmployee: Represents an employee paid based on sales commission.
BasePlusCommissionEmployee: Extends CommissionEmployee and includes a base salary.
PieceWorker: Represents an employee paid based on the number of pieces produced.

PayrollSystemTest Class: The main method serves as the entry point for the program.
Instances of each employee type are created (e.g., salariedEmployee, hourlyEmployee, etc.).
Individual information for each employee is displayed, including their name, SSN, and earnings.
An array of EmployeeClass is created, and instances of each employee type are stored in this array.
The program then processes these employees polymorphically, meaning it uses a common
interface (EmployeeClass) to interact with different types of employees. It iterates through the
array, invoking the toString method for each employee, adjusting base salary for
BasePlusCommissionEmployee, and displaying the earnings for each employee. Finally, the
program prints the type name of each object in the employees array using reflection.

Polymorphism: Polymorphism is demonstrated by treating all employee types as instances of


the common superclass EmployeeClass. This allows for generic processing of different types of
Page 4 of 8

employees in a uniform way. The program uses the instanceof operator to check if an employee
is of type BasePlusCommissionEmployee and adjusts the base salary accordingly.
Output:
The program generates output displaying individual and polymorphic processing of employees,
including their details and earnings.

Object Oriented Programming:

➢ Object-Oriented Programming (OOP) is a programming paradigm based on the concept of


"objects," which are instances of classes. This paradigm is widely used in software
development to structure and organize code in a way that reflects real-world entities and
their interactions. The key principles of object-oriented programming include
encapsulation, inheritance, and polymorphism. Here's an overview of these concepts:
➢ Classes and Objects:
o Class: A class is a blueprint or template for creating objects. It defines the
properties (attributes) and behaviors (methods) that the objects of the class will
have.
o Object: An object is an instance of a class. It represents a real-world entity and
encapsulates data and behaviors related to that entity.
➢ Encapsulation:
o Encapsulation is the bundling of data (attributes) and methods that operate on the
data within a single unit, i.e., a class. It allows the class to control access to its
internal details and hide the complexity from the outside.
➢ Inheritance:
o Inheritance is a mechanism that allows a class (subclass or derived class) to
inherit properties and behaviors from another class (superclass or base class). It
promotes code reuse and establishes a relationship between classes.
➢ Polymorphism:
o Polymorphism means "many forms." It allows objects of different classes to be
treated as objects of a common base class. Polymorphism enables a single
interface to represent different types of objects and their behaviors.

Code of Assignment 04:

Here is my program in Java:


Page 5 of 8

Fig.01(a): Input Code of PayRollSystem test


Page 6 of 8

Fig.01(b): Input Code of PieceWorker Class


Page 7 of 8

Output of Assignment:

Java program is verified by its output properly.

Fig.02: Verification of Output in Java


Page 8 of 8

So the output came as our desired requirement.

Summary:
The output confirms that the program run in Java are functioning as intended. The class
PieceWorker that calculates the employee’s earnings by multiplying the number of pieces
produced by the wage per piece.

Conclusion:

➢ The program generates output displaying individual and polymorphic processing of


employees, including their details and earnings.
➢ It showcases how polymorphism allows for the uniform processing of different types of
employees through a common interface.

You might also like