Question: / / Base class Person class Person { protected String name; protected int age; protected String address; public Person ( String name, int age, String
Base class Person
class Person
protected String name;
protected int age;
protected String address;
public PersonString name, int age, String address
this.name name;
this.age age;
this.address address;
public void printInfo
System.out.printlnName: name;
System.out.printlnAge: age;
System.out.printlnAddress: address;
Derived class Employee
class Employee extends Person
protected String employeeID;
protected String department;
protected double salary;
public EmployeeString name, int age, String address, String employeeID, String department, double salary
supername age, address;
this.employeeID employeeID;
this.department department;
this.salary salary;
@Override
public void printInfo
super.printInfo;
System.out.printlnEmployee ID: employeeID;
System.out.printlnDepartment: department;
System.out.printlnSalary: salary;
Derive class Manager
class Manager extends Employee
private final int teamSize;
private final double bonus;
public ManagerString name, int age, String address, String employeeID, String department, double salary, int teamSize, double bonus
supername age, address, employeeID, department, salary;
this.teamSize teamSize;
this.bonus bonus;
@Override
public void printInfo
super.printInfo;
System.out.printlnTeam Size: teamSize;
System.out.printlnBonus: $ bonus;
public double calculateTotalCompensation
return salary bonus;
Test Case
public class Main
public static void mainString args
Manager manager new ManagerJohn Diggle", Peyton Ln "Engineering", ;
manager.printInfo;
System.out.printlnTotal Compensation: $ manager.calculateTotalCompensation;
Using the code above you are to create the new files ReportGenerator.java and BonusStrategy.java
the new files ReportGenerator.java and BonusStrategy.java needs:
Single Responsibility Principle SRP:
Ensure that each class has only one reason to change by separating concerns. For instance, if the printInfo method is doing too much eg formatting and printing consider refactoring it into a separate class responsible for formatting.
OpenClosed Principle OCP:
The classes should be open for extension but closed for modification. Implement new functionality, such as calculating annual salary or providing different bonus strategies, by extending existing classes or adding new ones without modifying the existing code.
Liskov Substitution Principle LSP:
Ensure that objects of a superclass should be replaceable with objects of a subclass without affecting the functionality. For example, if you substitute an Employee object with a Manager object, it should not break the application.
Interface Segregation Principle ISP:
Refactor the code to use smaller, more specific interfaces rather than one large, generalpurpose interface. For example, you might create separate interfaces for Printable, Compensable, etc.
Dependency Inversion Principle DIP:
Refactor the code so that highlevel modules do not depend on lowlevel modules; both should depend on abstractions eg interfaces For example, the Manager class should depend on an IBonusStrategy interface rather than a concrete bonus calculation.
New Requirements:
Annual Salary Calculation:
Add a feature that calculates the annual salary for Employee and Manager objects. This should be implemented in a way that adheres to the OCP, allowing for different types of employees eg parttime, fulltime to have different salary calculations.
Bonus Strategy:
Implement different bonus strategies by creating a BonusStrategy interface. For example, a PerformanceBonusStrategy might give a higher bonus based on performance metrics.
Reporting:
Introduce a ReportGenerator class that follows the SRP This class should be responsible for generating reports eg summary of employee information rather than having this logic spread across the existing classes.
Interface Refactoring:
Create specific interfaces like Printable, Compensable, etc., to ensure that each class or module only depends on what it needs, adhering to the ISP.
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
