Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

More Books

Students also viewed these Databases questions

Question

How many multiples of 4 are there between 10 and 250?

Answered: 1 week ago

Question

How many three-digit numbers are divisible by 7?

Answered: 1 week ago

Question

Technology. Refer to Case

Answered: 1 week ago