Question: In this lab, you will extend the concepts from Lab 2 to add new functionality, role - specific compensation, and reporting based on departments and
In this lab, you will extend the concepts from Lab to add new functionality, rolespecific
compensation, and reporting based on departments and roles. The goal is to deepen your
understanding of SOLID principles, particularly OpenClosed Principle
OCP and Interface Segregation Principle ISP while introducing new features like
enums for roles and departments.
Key Objectives:
RoleBased Compensation:
o Add functionality to calculate different types of compensation based on the
employee's role.
o For instance:
Managers receive a PerformanceBased Bonus.
Engineers receive a ProjectBased Bonus.
Other roles may receive a Fixed Bonus.
o This should adhere to the OCP by extending the existing system rather than
modifying the core logic.
Enhancing Bonus Strategy:
o Use the BonusStrategy from Lab and extend it with different strategies for
each role:
PerformanceBonusStrategy for Managers.
ProjectBonusStrategy for Engineers.
FixedBonusStrategy for other roles.
o This ensures the BonusStrategy interface is scalable for future rolespecific
bonuses.
Enhanced Reporting:
o Extend the ReportGenerator class to generate reports based on roles and
departments.
o Ensure that this class can generate reports for:
Specific employee roles eg report only for managers
Specific departments eg report only for the Engineering
department
Interface Enhancements:
o Continue using specific interfaces like Printable and Compensable.
o Ensure rolespecific logic is handled through new interfaces where needed,
adhering to ISP.
RoleSpecific Behaviors with Enums:
o Introduce Enums for roles and departments:
Department Enum: Includes categories like IT Engineering, HR
Sales, and Marketing.
Role Enum: Includes roles like Manager, Engineer,
HRRepresentative, and SalesPerson.
o Each role may have different working hours, team sizes, or other rolespecific
behaviors that can be reflected using these enums.
StepbyStep Guide to Implementing the Solution
Create Role and Department Enums: These enums will categorize employees and
help manage rolespecific behaviors.
Code Example:
Enum example provided in slides:
Define an enum named 'DaysOfWeek'
enum DaysOfWeek
Define enum constants
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY,
SUNDAY
Make similar enums for:
Department Enum: Includes categories like IT Engineering, HR Sales, and
Marketing.
Role Enum: Includes roles like Manager, Engineer,
HRRepresentative, and SalesPerson.
Example usage should look like this:
Role role Role.MANAGER; Use the Role enum
Department department Department.IT;
Implement RoleSpecific Bonus Strategies: Enhance the
existing BonusStrategy interface to handle different bonus structures for each role.
BonusStrategy Interface:
public interface BonusStrategy
double calculateBonusdouble salary;
PerformanceBonusStrategy for Managers:
public class PerformanceBonusStrategy implements BonusStrategy
@Override
public double calculateBonusdouble salary
return salary ; Managers get a performancebased bonus
ProjectBonusStrategy for Engineers:
public class ProjectBonusStrategy implements BonusStrategy
@Override
public double calculateBonusdouble salary
return salary ; Engineers get a projectbased bonus
FixedBonusStrategy for Other Roles:
public class FixedBonusStrategy implements BonusStrategy
@Override
public double calculateBonusdouble salary
return ; Fixed bonus for other roles
RoleSpecific Reporting: Extend the ReportGenerator to generate reports based
on the employees role or department.
Code Example:
public class ReportGenerator
public void generateReportByRoleRole role, List employees
for Employee employee : employees
if employeegetRoleequalsrole
System.out.printlnEmployee: employee.getName Role:
employee.getRole;
public void generateReportByDepartmentDepartment department, List
employees
for Employee employee : employees
if employeegetDepartmentequalsdepartment
System.out.printlnEmployee: employee.getName Department:
employee.getDepartment;
Extend Interfaces for RoleSpecific Logic: Continue using interfaces
like Printable and Compensable, and extend them for rolespecific logic.
Code Example:
public interface RoleSpecific
void performRoleSpecificTask;
public class Manager implements RoleSpecific
@Override
public void performRoleSpecificTask
System.out.printlnManager is leading the team.";
public class Engineer implements RoleSpecific
@Override
public void performRoleSpecificTask
System.out.printlnEngineer is developing the project.";
Create EmployeeFactory to Generate RoleSpecific Employees: Implement
an EmployeeFactory to create employees based on their role and department.
Code Example:
public class EmployeeFactory
public static Employee createEmployeeString
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
