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 Person(String name, int age, String address){
this.name = name;
this.age = age;
this.address = address;
}
public void printInfo(){
System.out.println("Name: "+ name);
System.out.println("Age: "+ age);
System.out.println("Address: "+ address);
}
}
// Derived class Employee
class Employee extends Person {
protected String employeeID;
protected String department;
protected double salary;
public Employee(String name, int age, String address, String employeeID, String department, double salary){
super(name, age, address);
this.employeeID = employeeID;
this.department = department;
this.salary = salary;
}
@Override
public void printInfo(){
super.printInfo();
System.out.println("Employee ID: "+ employeeID);
System.out.println("Department: "+ department);
System.out.println("Salary: "+ salary);
}
}
//Derive class Manager
class Manager extends Employee {
private final int teamSize;
private final double bonus;
public Manager(String name, int age, String address, String employeeID, String department, double salary, int teamSize, double bonus){
super(name, age, address, employeeID, department, salary);
this.teamSize = teamSize;
this.bonus = bonus;
}
@Override
public void printInfo(){
super.printInfo();
System.out.println("Team Size: "+ teamSize);
System.out.println("Bonus: $"+ bonus);
}
public double calculateTotalCompensation(){
return salary + bonus;
}
}
// Test Case
public class Main {
public static void main(String[] args){
Manager manager = new Manager("John Diggle", 30,"265 Peyton Ln","30265", "Engineering", 85000,6,5000);
manager.printInfo();
System.out.println("Total 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 (e.g., formatting and printing), consider refactoring it into a separate class responsible for formatting.
Open/Closed 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, general-purpose interface. For example, you might create separate interfaces for Printable, Compensable, etc.
Dependency Inversion Principle (DIP):
Refactor the code so that high-level modules do not depend on low-level modules; both should depend on abstractions (e.g., 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 (e.g., part-time, full-time) 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 (e.g., 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 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!