Question
Suppose a company has two types of workers working for them - HourlyEmployee and FullTimeEmployee. The hourly employees are paid on hourly basis and they
Suppose a company has two types of workers working for them - HourlyEmployee and FullTimeEmployee. The hourly employees are paid on hourly basis and they work 40 hours a week whereas, full time employees are paid on monthly basis. Given the below code implementations for HourlyEmployee and FullTimeEmployee class and a client program EmployeeTest class that is a client of HourlyEmployee and FullTimeEmployee, evaluate code design to check whether the design follows Open-Close and Liskov Substitution Principle. Your argument should provide appropriate explanation for whether these design principles are followed or violated. If your evaluation states that the given code design violates either or both of the design principles, explain what needs to be done in terms of the changing the design. Provide a class diagram of the improved design.
public interface Employee
{
//this is an empty interface with no methods.
}
//SalariedEmployee represents a fulltime employee
public class FullTimeEmployee implements Employee
{
private int annualSalary;
public FullTimeEmployee(int sal)
{
annualSalary = sal;
}
public double salaryFullTimeEmployee()
{
return annualSalary/12;
}
}
public class HourlyWageEmployee implements Employee
{
//hourly wage rate
private int wageRate;
public HourlyWageEmployee(double wage)
{
wageRate = wage;
}
//salary( ) method returns the weekly salary
//
public int salaryHourlyWageEmployee()
{
return 40 * wageRate;
}
}
//client program using the Employee types
public class EmployeeTest
{
public double returnSalary(Employee e )
{
if(e instanceof FullTimeEmployee)
{
FullTimeEmployee s = (FullTimeEmployee) e;
return s.salaryFullTimeEmployee();
}
else
{
HourlyWageEmployee h = (HourlyWageEmployee) e;
return h.salaryHourlyWageEmployee();
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started