Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

For this assignment, you are going to enhance the Employee Hierarchy that you created in Programming Assignment 2 by adding an interface called Compensation with the following two methods: earnings()...

1 answer below »

For this assignment, you are going to enhance the Employee Hierarchy that you created in Programming Assignment 2 by adding an interface called Compensation with the following two methods:

  • earnings() - receives no parameters and returns a double.
  • raise(double percent) - receives one parameter which is the percentage of the raise and returns a void.

Create the abstract class CompensationModel which implements the Compensation interface. Create the following classes as subclasses of CompensationModel:

  • SalariedCompensationModel - For Employees who are paid a fixed weekly salary, this class should contain a weeklySalary instance variable, and should implement methods earnings() to return the weekly salary, and raise(double percent) which increases the weekly salary by the percent specified.
  • HourlyCompensationModel - For Employees who are paid by the hour and receive overtime pay for all hours worked in excess of 40 hours per week. This class should contain instance variables of wage and hours and should implement method earnings() based on the number of hours worked. For any hours worked over 40, they should be paid at an hourly wage of 1 and a half times their wage. So if their normal wage is $10 per hour normally, they would get $15 per hour for overtime. It should also implement the methodraise(double percent) by increasing the wage by the percent specified.
  • CommissionCompensationModel - This class is the same as in Asssignment 2 except that this class is now a subclass of CompensationModel.It should also implement the methodraise(double percent) by increasing the commission rate by the percent specified.
  • BasePlusCommissionCompensationModel - This class is the same as in Assignment 2, a subclass ofCommissionCompensationModel.It should also implement the methodraise(double percent) by increasing the base salary and commission rate by the percent specified.

Each of these classes will also have a toString() method to display their compensation information as illustrated in the sample output below.

Modify the Employee class of Assignment 2 to have an instance variable of type CompensationModel instead of CommissionCompensationModel, Make any other necessary changes in the Employee class because of this. Also add the raise (double percent) method to the Employee class which simply calls the raise method of the CompensationModel.

Use the following code in your main function to test your classes, just copy and paste it into your main method:

// Create the four employees with their compensation models.
CommissionCompensationModel commissionModel = new CommissionCompensationModel XXXXXXXXXX, 0.04);
BasePlusCommissionCompensationModel basePlusCommissionModel = new BasePlusCommissionCompensationModel XXXXXXXXXX, 0.05, 600.00);
SalariedCompensationModel salariedCompensationModel = new SalariedCompensationModel XXXXXXXXXX);
HourlyCompensationModel hourlyCommissionModel = new HourlyCompensationModel(10.00, 35.0);
Employee employee1 = new Employee("John", "Smith", " XXXXXXXXXX", commissionModel);
Employee employee2 = new Employee("Sue", "Jones", " XXXXXXXXXX", basePlusCommissionModel);
Employee employee3 = new Employee("Jim", "Williams", " XXXXXXXXXX", salariedCompensationModel);
Employee employee4 = new Employee("Nancy", "Johnson", " XXXXXXXXXX", hourlyCommissionModel);
// Print the information about the four employees.
System.out.println("The employee information initially.");
System.out.printf("%s%n%s%n%s%n%s%n", employee1, employee2, employee3, employee4);
System.out.printf("%s%s%s%s%s%8.2f%n%n", "Earnings for ", employee1.getFirstName(), " ", employee1.getLastName(), ": ", employee1.earnings());
// Change the compensation model for the four employees.
CommissionCompensationModel commissionModelNew = new CommissionCompensationModel XXXXXXXXXX, 0.04);
BasePlusCommissionCompensationModel basePlusCommissionModelNew = new BasePlusCommissionCompensationModel XXXXXXXXXX, 0.05, 800.00);
SalariedCompensationModel salariedCompensationModelNew = new SalariedCompensationModel XXXXXXXXXX);
HourlyCompensationModel hourlyCommissionModeNewl = new HourlyCompensationModel(10.00, 50);
// Set the new compensation models for the employees.
employee1.setCompensation(basePlusCommissionModelNew);
employee2.setCompensation(commissionModelNew);
employee3.setCompensation(hourlyCommissionModeNewl);
employee4.setCompensation(salariedCompensationModelNew);
// Print out the new information for the four employees.
System.out.println("The employee information after changing compensation models.");
System.out.printf("%s%n%s%n%s%n%s%n", employee1, employee2, employee3, employee4);
// Declare an array of employees and assign the four employees to it.
Employee[] employees = new Employee[4];
employees[0] = employee1;
employees[1] = employee2;
employees[2] = employee3;
employees[3] = employee4;
// Loop thru the array giving each employee a 2% raise polymorphically;
for (Employee employee : employees)
{
employee.raise(.02);
}
// Print out their new earnings.
System.out.println("The employee information after raises of 2 percent.");
System.out.printf("%s%n%s%n%s%n%s%n", employee1, employee2, employee3, employee4);

The output from your program should look like the following (there will be additional blank lines in the output which canvas removes for me, unwanted, in this display):

run:
The employee information initially.
John Smith
Social Security Number: XXXXXXXXXX
Commission Compensation with:
Gross Sales of: XXXXXXXXXX
Commission Rate of: 0.040
Earnings: 80.00Sue Jones
Social Security Number: XXXXXXXXXX
Base Plus Commission Compensation with:
Gross Sales of: XXXXXXXXXX
Commission Rate of: 0.050
Base Salary of: 600.00
Earnings: 700.00Jim Williams
Social Security Number: XXXXXXXXXX
Salaried Compensation with:
Weekly Salary of: XXXXXXXXXX
Earnings: 2500.00Nancy Johnson
Social Security Number: XXXXXXXXXX
Hourly Compensation with:
Wage of: 10.00
Hours Worked of:35.00
Earnings: 350.00Earnings for John Smith: 80.00The employee information after changing compensation models.
John Smith
Social Security Number: XXXXXXXXXX
Base Plus Commission Compensation with:
Gross Sales of: XXXXXXXXXX
Commission Rate of: 0.050
Base Salary of: 800.00
Earnings: 1000.00Sue Jones
Social Security Number: XXXXXXXXXX
Commission Compensation with:
Gross Sales of: XXXXXXXXXX
Commission Rate of: 0.040
Earnings: 200.00Jim Williams
Social Security Number: XXXXXXXXXX
Hourly Compensation with:
Wage of: 10.00
Hours Worked of:50.00
Earnings: 550.00Nancy Johnson
Social Security Number: XXXXXXXXXX
Salaried Compensation with:
Weekly Salary of: XXXXXXXXXX
Earnings: 3500.00The employee information after raises of 2 percent.
John Smith
Social Security Number: XXXXXXXXXX
Base Plus Commission Compensation with:
Gross Sales of: XXXXXXXXXX
Commission Rate of: 0.051
Base Salary of: 816.00
Earnings: 1020.00Sue Jones
Social Security Number: XXXXXXXXXX
Commission Compensation with:
Gross Sales of: XXXXXXXXXX
Commission Rate of: 0.041
Earnings: 204.00Jim Williams
Social Security Number: XXXXXXXXXX
Hourly Compensation with:
Wage of: 10.20
Hours Worked of:50.00
Earnings: 561.00Nancy Johnson
Social Security Number: XXXXXXXXXX
Salaried Compensation with:
Weekly Salary of: XXXXXXXXXX
Earnings: XXXXXXXXXX
Answered Same Day Sep 24, 2021

Solution

Aditya answered on Sep 24 2021
143 Votes
Employee
uild.xml

Builds, tests, and runs the project Employee.


Employee
uild/classes/.netbeans_automatic_build
Employee
uild/classes/.netbeans_update_resources
Employee
uild/classes/BasePlusCommissionCompensationModel.class
public synchronized class BasePlusCommissionCompensationModel extends CommissionCompensationModel {
private double basicSalary;
public void BasePlusCommissionCompensationModel(double, double, double);
public double earnings();
public String toString();
public void raise(double);
}
Employee
uild/classes/CommissionCompensationModel.class
synchronized class CommissionCompensationModel extends CompensationModel {
protected double grossSales;
protected double CommisionRate;
public void CommissionCompensationModel(double, double);
public double earnings();
public void raise(double);
public String toString();
}
Employee
uild/classes/Compensation.class
public abstract interface Compensation {
public abstract double earnings();
public abstract void raise(double);
}
Employee
uild/classes/CompensationModel.class
abstract synchronized class CompensationModel implements Compensation {
public void CompensationModel();
}
Employee
uild/classes/Employee.class
public synchronized class Employee {
private String firstName;
private String lastName;
private String sNumber;
private CompensationModel compensationModel;
public void Employee(String, String, String, CompensationModel);
public String getFirstName();
public void setFirstName(String);
public String getLastName();
public void setLastName(String);
public String getsNumber();
public void setsNumber(String);
public CompensationModel getCompensationModel();
public void setCompensation(CompensationModel);
public double earnings();
public String toString();
void raise(double);
}
Employee
uild/classes/HourlyCompensationModel.class
public synchronized class HourlyCompensationModel extends CompensationModel {
private double wage;
private double hour;
public void HourlyCompensationModel(double, double);
public double earnings();
public void raise(double);
public double getWage();
public void setWage(double);
public double getHour();
public void setHour(float);
public String toString();
}
Employee
uild/classes/main.class
public synchronized class main {
public void main();
public static void main(String[]);
}
Employee
uild/classes/SalariedCompensationModel.class
public synchronized class SalariedCompensationModel extends CompensationModel {
private double weeklySalary;
public void SalariedCompensationModel(double);
public double earnings();
public void raise(double);
public String toString();
}
Employee/manifest.mf
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
Employee/nbproject
uild-impl.xml








































































































































































































Must set src.di
Must set test.src.di
Must set build.di
Must set dist.di
Must set build.classes.di
Must set dist.javadoc.di
Must set build.test.classes.di
Must set build.test.results.di
Must set build.classes.excludes
Must set dist.ja




































































































Must set javac.includes
































































































































No tests executed.














































...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here