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 2 to add new functionality, role-specific
compensation, and reporting based on departments and roles. The goal is to deepen your
understanding of SOLID principles, particularly Open/Closed Principle
(OCP) and Interface Segregation Principle (ISP), while introducing new features like
enums for roles and departments.
Key Objectives:
1. Role-Based Compensation:
o Add functionality to calculate different types of compensation based on the
employee's role.
o For instance:
Managers receive a Performance-Based Bonus.
Engineers receive a Project-Based 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.
2. Enhancing Bonus Strategy:
o Use the BonusStrategy from Lab 2 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 role-specific
bonuses.
3. 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 (e.g., report only for managers).
Specific departments (e.g., report only for the Engineering
department).
4. Interface Enhancements:
o Continue using specific interfaces like Printable and Compensable.
o Ensure role-specific logic is handled through new interfaces where needed,
adhering to ISP.
5. Role-Specific 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,
HR_Representative, and SalesPerson.
o Each role may have different working hours, team sizes, or other role-specific
behaviors that can be reflected using these enums.
Step-by-Step Guide to Implementing the Solution
1. Create Role and Department Enums: These enums will categorize employees and
help manage role-specific 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,
HR_Representative, and SalesPerson.
Example usage should look like this:
Role role = Role.MANAGER; // Use the Role enum
Department department = Department.IT;
Implement Role-Specific Bonus Strategies: Enhance the
existing BonusStrategy interface to handle different bonus structures for each role.
BonusStrategy Interface:
public interface BonusStrategy {
double calculateBonus(double salary);
}
PerformanceBonusStrategy for Managers:
public class PerformanceBonusStrategy implements BonusStrategy {
@Override
public double calculateBonus(double salary){
return salary *0.20; // Managers get a 20% performance-based bonus
}
}
ProjectBonusStrategy for Engineers:
public class ProjectBonusStrategy implements BonusStrategy {
@Override
public double calculateBonus(double salary){
return salary *0.15; // Engineers get a 15% project-based bonus
}
}
FixedBonusStrategy for Other Roles:
public class FixedBonusStrategy implements BonusStrategy {
@Override
public double calculateBonus(double salary){
return 500; // Fixed bonus for other roles
}
}
2. Role-Specific Reporting: Extend the ReportGenerator to generate reports based
on the employees role or department.
Code Example:
public class ReportGenerator {
public void generateReportByRole(Role role, List employees){
for (Employee employee : employees){
if (employee.getRole().equals(role)){
System.out.println("Employee: "+ employee.getName()+"- Role: "+
employee.getRole());
}
}
}
public void generateReportByDepartment(Department department, List
employees){
for (Employee employee : employees){
if (employee.getDepartment().equals(department)){
System.out.println("Employee: "+ employee.getName()+"- Department: "+
employee.getDepartment());
}
}
}
}
3. Extend Interfaces for Role-Specific Logic: Continue using interfaces
like Printable and Compensable, and extend them for role-specific logic.
Code Example:
public interface RoleSpecific {
void performRoleSpecificTask();
}
public class Manager implements RoleSpecific {
@Override
public void performRoleSpecificTask(){
System.out.println("Manager is leading the team.");
}
}
public class Engineer implements RoleSpecific {
@Override
public void performRoleSpecificTask(){
System.out.println("Engineer is developing the project.");
}
}
4. Create EmployeeFactory to Generate Role-Specific Employees: Implement
an EmployeeFactory to create employees based on their role and department.
Code Example:
public class EmployeeFactory {
public static Employee createEmployee(String

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!