Question

In: Computer Science

Assignment 3 - Enhanced Employee Hierarchy For this assignment, you are going to enhance the Employee...

Assignment 3 - Enhanced Employee Hierarchy

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 method raise(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 method raise(double percent) by increasing the commission rate by the percent specified.
  • BasePlusCommissionCompensationModel - This class is the same as in Assignment 2, a subclass of CommissionCompensationModel . It should also implement the method raise(double percent) by increasing the base salary 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(2000.00, 0.04);
        BasePlusCommissionCompensationModel basePlusCommissionModel = new BasePlusCommissionCompensationModel(2000.00, 0.05, 600.00);
        SalariedCompensationModel salariedCompensationModel = new SalariedCompensationModel(2500.00);
        HourlyCompensationModel hourlyCommissionModel = new HourlyCompensationModel(10.00, 35.0);
       
        Employee employee1 = new Employee("John", "Smith", "111-11-1111", commissionModel);
        Employee employee2 = new Employee("Sue", "Jones", "222-22-2222", basePlusCommissionModel);
        Employee employee3 = new Employee("Jim", "Williams", "333-33-3333", salariedCompensationModel);
        Employee employee4 = new Employee("Nancy", "Johnson", "444-44-4444", 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(5000.00, 0.04);
        BasePlusCommissionCompensationModel basePlusCommissionModelNew = new BasePlusCommissionCompensationModel(4000.00, 0.05, 800.00);
        SalariedCompensationModel salariedCompensationModelNew = new SalariedCompensationModel(3500.00);
        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: 111-11-1111
Commission Compensation with:
Gross Sales of: 2000.00
Commission Rate of: 0.04
Earnings:    80.00

Sue Jones
Social Security Number: 222-22-2222
Base Plus Commission Compensation with:
Gross Sales of: 2000.00
Commission Rate of: 0.05
Base Salary of:   600.00
Earnings:   700.00

Jim Williams
Social Security Number: 333-33-3333
Salaried Compensation with:
Weekly Salary of: 2500.00
Earnings: 2500.00

Nancy Johnson
Social Security Number: 444-44-4444
Hourly Compensation with:
Wage of:    10.00
Hours Worked of:35.00
Earnings:   350.00

Earnings for John Smith:    80.00

The employee information after changing compensation models.
John Smith
Social Security Number: 111-11-1111
Base Plus Commission Compensation with:
Gross Sales of: 4000.00
Commission Rate of: 0.05
Base Salary of:   800.00
Earnings: 1000.00

Sue Jones
Social Security Number: 222-22-2222
Commission Compensation with:
Gross Sales of: 5000.00
Commission Rate of: 0.04
Earnings:   200.00

Jim Williams
Social Security Number: 333-33-3333
Hourly Compensation with:
Wage of:    10.00
Hours Worked of:50.00
Earnings:   550.00

Nancy Johnson
Social Security Number: 444-44-4444
Salaried Compensation with:
Weekly Salary of: 3500.00
Earnings: 3500.00

The employee information after raises of 2 percent.
John Smith
Social Security Number: 111-11-1111
Base Plus Commission Compensation with:
Gross Sales of: 4000.00
Commission Rate of: 0.05
Base Salary of:   816.00
Earnings: 1016.00

Sue Jones
Social Security Number: 222-22-2222
Commission Compensation with:
Gross Sales of: 5000.00
Commission Rate of: 0.04
Earnings:   204.00

Jim Williams
Social Security Number: 333-33-3333
Hourly Compensation with:
Wage of:    10.20
Hours Worked of:50.00
Earnings:   561.00

Nancy Johnson
Social Security Number: 444-44-4444
Salaried Compensation with:
Weekly Salary of: 3570.00
Earnings: 3570.00

PreviousNext

Solutions

Expert Solution

/**********************************Employee.java******************************/

package assignment2;


/**
*
* @author usagi
*/
public class Employee extends CompensationModel {
   private String firstName;
   private String lastName;
   private String socialSecurityNumber;
   private CompensationModel compensation;

   public Employee(String firstName, String lastName, String socialSecurityNumber,
           CompensationModel commissionModel) {
       this.firstName = firstName;
       this.lastName = lastName;
       this.socialSecurityNumber = socialSecurityNumber;
       this.compensation = commissionModel;
   }

   public double earnings() {
       return this.compensation.earnings();
   }

   public void setCompensation(CompensationModel compensation) {
       this.compensation = compensation;
   }

   public String getFirstName() {
       return firstName;
   }

   public String getLastName() {
       return lastName;
   }

   public String getSocialSecurityNumber() {
       return socialSecurityNumber;
   }

   public CompensationModel getCompensation() {
       return compensation;
   }

   @Override
   public String toString() {
       String str = "";
       str = str + firstName + " " + lastName;
       str = str + "\nSocial Security Number: " + socialSecurityNumber;
       str = str + compensation.toString();
       return str;
   }

   @Override
   public void raise(double percent) {
      
       this.compensation.raise(percent);
   }
}
/******************************************Compensation.java*****************************/

package assignment2;

// TODO: Auto-generated Javadoc
/**
* The Interface Compensation.
*/
public interface Compensation {

   /**
   * Earnings.
   *
   * @return the double
   */
   public double earnings();

   /**
   * Raise.
   *
   * @param percent the percent
   */
   public void raise(double percent);
  
}
/***********************************************CommisionModel.java*************************/

package assignment2;

/**
* The Class CompensationModel.
*/
public abstract class CompensationModel implements Compensation {

   private double grossSales;
   private double commissionRate;

   public CompensationModel() {

       this.grossSales = 0;
       this.commissionRate = 0;
   }

   public CompensationModel(double grossSales, double commissionRate) {
       super();
       this.grossSales = grossSales;
       this.commissionRate = commissionRate;
   }

   public double getGrossSales() {
       return grossSales;
   }

   public void setGrossSales(double grossSales) {
       this.grossSales = grossSales;
   }

   public double getCommissionRate() {
       return commissionRate;
   }

   public void setCommissionRate(double commissionRate) {
       this.commissionRate = commissionRate;
   }

   @Override
   public String toString() {
       String str = "\nCommission Compensation with: ";
       str = str + "\nGross Sales of: " + grossSales;
       str = str + "\nCommission Rate of: " + commissionRate;
       str = str + "\nEarnings: " + earnings();
       return str;
   }

}
/**************************************BasePlusCommissionCompensationModel.java**************************/

package assignment2;

/**
* The Class BasePlusCommissionCompensationModel.
*/
public class BasePlusCommissionCompensationModel extends CompensationModel {

   /** The salary. */
   private double salary;

   public BasePlusCommissionCompensationModel(double grossSales, double commissionRate, double baseSalary) {

       super(grossSales, commissionRate);
       this.salary = baseSalary;
   }

   @Override
   public double earnings() {

       return salary+getGrossSales()*getCommissionRate();
   }

   @Override
   public void raise(double percent) {

       salary += salary * percent;
   }

   @Override
   public String toString() {
       String str = "\nBase Plus Commission Compensation with: ";
       str = str + "\nGross Sales of: " + getGrossSales();
       str = str + "\nCommission Rate of: " + getCommissionRate();
       str = str + "\nBase Salary of: " + salary;
       str = str + "\nEarnings: " + earnings();
       return str;
   }

}
/************************************************CommissionCompensationModel.java****************************/

package assignment2;

/**
* The Class CommissionCompensationModel.
*/
public class CommissionCompensationModel extends CompensationModel {

   public CommissionCompensationModel(double grossSales, double commissionRate) {
       super(grossSales, commissionRate);

   }

   @Override
   public double earnings() {

       return getGrossSales() * getCommissionRate();

   }

   @Override
   public void raise(double percent) {

       setCommissionRate(getCommissionRate() + getCommissionRate() * percent);
   }

   @Override
   public String toString(){
   String str = "\nCommission Compensation with: ";
   str = str + "\nGross Sales of: " + getGrossSales();
   str = str + "\nCommission Rate of: " + getCommissionRate();
   str = str + "\nEarnings: " + earnings();
   return str;
   }
}
/****************************************SalariedCompensationModel.java****************************/

package assignment2;

// TODO: Auto-generated Javadoc
/**
* The Class SalariedCompensationModel.
*/
public class SalariedCompensationModel extends CompensationModel {

   /** The weekly salary. */
   private double weeklySalary;

   public SalariedCompensationModel(double weeklySalary) {
       this.weeklySalary = weeklySalary;
   }

   @Override
   public double earnings() {

       return weeklySalary;
   }

   @Override
   public void raise(double percent) {

       weeklySalary += weeklySalary * percent;
   }


   @Override
   public String toString() {
       String str = "\nSalaried Compensation with: ";
       str = str + "\nWeekly Salary of: "+weeklySalary;
       str = str + "\nEarnings: " + earnings();
       return str;
   }
}
/*****************************************HourlyCompensationModel.java*****************************/

package assignment2;

// TODO: Auto-generated Javadoc
/**
* The Class HourlyCompensationModel.
*/
public class HourlyCompensationModel extends CompensationModel {

   /** The wage. */
   private double wage;

   /** The hours. */
   private double hours;

   public HourlyCompensationModel(double wage, double hours) {
       super();
       this.wage = wage;
       this.hours = hours;
   }

   @Override
   public double earnings() {

       double earnings = 0;
       if (hours <= 40) {

           earnings = wage * hours;
       } else if (hours > 40) {

           earnings = 40 * wage + (hours - 40) * 1.5 * wage;
       }
       return earnings;
   }

   @Override
   public void raise(double percent) {

       wage += wage * percent;
   }

   @Override
   public String toString() {
       String str = "\nHourly Compensation with: ";
       str = str + "\nWage of: : " + wage;
       str = str + "\nHours Worked of: " + hours;
       str = str + "\nEarnings: " + earnings();
       return str;
   }
}
/*******************************************EmployeeHierarchy.java******************************/

package assignment2;

/**
*
* @author usagi
*/
public class EmployeeHierarchy {

   /**
   * @param args the command line arguments
   */
   public static void main(String[] args) {
       // Create the two employees with their compensation models.

       CommissionCompensationModel commissionModel = new CommissionCompensationModel(2000.00, 0.04);
       BasePlusCommissionCompensationModel basePlusCommissionModel = new BasePlusCommissionCompensationModel(2000.00,
               0.05, 600.00);
       SalariedCompensationModel salariedCompensationModel = new SalariedCompensationModel(2500.00);
       HourlyCompensationModel hourlyCommissionModel = new HourlyCompensationModel(10.00, 35.0);

       Employee employee1 = new Employee("John", "Smith", "111-11-1111", commissionModel);
       Employee employee2 = new Employee("Sue", "Jones", "222-22-2222", basePlusCommissionModel);
       Employee employee3 = new Employee("Jim", "Williams", "333-33-3333", salariedCompensationModel);
       Employee employee4 = new Employee("Nancy", "Johnson", "444-44-4444", 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(5000.00, 0.04);
       BasePlusCommissionCompensationModel basePlusCommissionModelNew = new BasePlusCommissionCompensationModel(
               4000.00, 0.05, 800.00);
       SalariedCompensationModel salariedCompensationModelNew = new SalariedCompensationModel(3500.00);
       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);
   }

}
/********************output**********************/

The employee information initially.
John Smith
Social Security Number: 111-11-1111
Commission Compensation with:
Gross Sales of: 2000.0
Commission Rate of: 0.04
Earnings: 80.0
Sue Jones
Social Security Number: 222-22-2222
Base Plus Commission Compensation with:
Gross Sales of: 2000.0
Commission Rate of: 0.05
Base Salary of: 600.0
Earnings: 700.0
Jim Williams
Social Security Number: 333-33-3333
Salaried Compensation with:
Weekly Salary of: 2500.0
Earnings: 2500.0
Nancy Johnson
Social Security Number: 444-44-4444
Hourly Compensation with:
Wage of: : 10.0
Hours Worked of: 35.0
Earnings: 350.0
Earnings for John Smith: 80.00

The employee information after changing compensation models.
John Smith
Social Security Number: 111-11-1111
Base Plus Commission Compensation with:
Gross Sales of: 4000.0
Commission Rate of: 0.05
Base Salary of: 800.0
Earnings: 1000.0
Sue Jones
Social Security Number: 222-22-2222
Commission Compensation with:
Gross Sales of: 5000.0
Commission Rate of: 0.04
Earnings: 200.0
Jim Williams
Social Security Number: 333-33-3333
Hourly Compensation with:
Wage of: : 10.0
Hours Worked of: 50.0
Earnings: 550.0
Nancy Johnson
Social Security Number: 444-44-4444
Salaried Compensation with:
Weekly Salary of: 3500.0
Earnings: 3500.0
The employee information after raises of 2 percent.
John Smith
Social Security Number: 111-11-1111
Base Plus Commission Compensation with:
Gross Sales of: 4000.0
Commission Rate of: 0.05
Base Salary of: 816.0
Earnings: 1016.0
Sue Jones
Social Security Number: 222-22-2222
Commission Compensation with:
Gross Sales of: 5000.0
Commission Rate of: 0.0408
Earnings: 204.00000000000003
Jim Williams
Social Security Number: 333-33-3333
Hourly Compensation with:
Wage of: : 10.2
Hours Worked of: 50.0
Earnings: 561.0
Nancy Johnson
Social Security Number: 444-44-4444
Salaried Compensation with:
Weekly Salary of: 3570.0
Earnings: 3570.0

Please let me know if you have any doubt or modify the answer, Thanks :)


Related Solutions

Assignment 3 - Enhanced Employee Hierarchy For this assignment, you are going to enhance the Employee...
Assignment 3 - Enhanced Employee Hierarchy For this assignment, you are going to enhance the Employee Hierarchy that you created in Java 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...
Assignment 2 - Employee Hierarchy In Chapter 9, we created the CommissionEmployee-BasePlusCommissionEmployee inheritance hierarchy to model...
Assignment 2 - Employee Hierarchy In Chapter 9, we created the CommissionEmployee-BasePlusCommissionEmployee inheritance hierarchy to model the relationship between two types of employees and how to calculate the earnings for each. Another way to look at the problem is that CommissionEmployees and BasePlusCommissionEmployees are each Employees and that each has a different CompensationModel object. A CompensationModel would provide an earnings method. Classes or subclasses of CompensationModel would contain the details of a particular Employee's compensation: CommissionCompensationModel - For Employees who...
In this assignment you are going to use the menu you created in Assignment 1 to...
In this assignment you are going to use the menu you created in Assignment 1 to test both your Double and Integer classes. You should add functionality to the menu to allow you test the add, sub, mul, div functions for instances of both classes You are going to have make a modification to your menu class. Currently it uses an array to hold a fixed amount of menu items. While this may be OK for most applications we want...
For this assignment, you will create a hierarchy of five classes to describe various elements of...
For this assignment, you will create a hierarchy of five classes to describe various elements of a school setting. The classes you will write are: Person, Student,Teacher, HighSchoolStudent, and School. Detailed below are the requirements for the variables and methods of each class. You may need to add a few additional variables and/or methods; figuring out what is needed is part of your task with this assignment. Person Variables: String firstName - Holds the person's first name String lastName -...
Assignment 1 – Writing a Linux Utility Program Instructions For this programming assignment you are going...
Assignment 1 – Writing a Linux Utility Program Instructions For this programming assignment you are going to implement a simple C version of the UNIX cat program called lolcat. The cat program allows you to display the contents of one or more text files. The lolcat program will only display one file. The correct usage of your program should be to execute it on the command line with a single command line argument consisting of the name you want to...
CS 400 Assignment 2: applying ArrayList In this assignment, you are going to build a program...
CS 400 Assignment 2: applying ArrayList In this assignment, you are going to build a program that can help rental car companies to manage their rental fleet. Requirement: - build ArrayList class as container. - build Car class/structure to represent car objects. - An ArrayList object is to hold Car objects. Car class should have following fields: - id (int) - make (string) - model (string) - color (string) Instructions: - make up 15 cars and save them into a...
This assignment will use the Employee class that you developed for assignment 6. Design two subclasses...
This assignment will use the Employee class that you developed for assignment 6. Design two subclasses of Employee…SalariedEmployee and HourlyEmployee. A salaried employee has an annual salary attribute. An hourly employee has an hourly pay rate attribute, an hours worked attribute, and an earnings attribute. An hourly employee that works more than 40 hours gets paid at 1.5 times their hourly pay rate. You will decide how to implement constructors, getters, setters, and any other methods that might be necessary....
**JAVA LANGUAGE** This assignment will use the Employee class that you developed for assignment 6. Design...
**JAVA LANGUAGE** This assignment will use the Employee class that you developed for assignment 6. Design two sub- classes of Employee...FullTimeEmployee and HourlyEmployee. A full-time employee has an annual salary attribute and may elect to receive life insurance. An hourly employee has an hourly pay rate attribute, an hours worked attribute for the current pay period, a total hours worked attribute for the current year, a current earnings attribute (for current pay period), a cumulative earnings attribute (for the current...
PURPOSE: The purpose of this assignment is to enable the students to enhance their knowledge on...
PURPOSE: The purpose of this assignment is to enable the students to enhance their knowledge on the environmental engineering and sustainable development for environmental engineering. TASK 1 (DOCUMENTATION) Development in science and technology has increase the level of human lifestyle which leads to technology advancement. However, everything good comes with a price. One of the greatest problems that the world is facing today is that of environmental pollution, increasing with every passing year and causing grave and irreparable damage to...
Guiding principles to bring about a shift in employee morale and enhance productivity
Guiding principles to bring about a shift in employee morale and enhance productivity
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT