subject

Assignment 2 - Employee Hierarchy In Chapter 9, we created the CommissionEmployee- 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 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:
- For Employees who are paid by commission, the class would contain grossSales and commissionRate instance variables, and would define an earnings method to return grossSales * commissionRate.
- For Employees who are paid a base salary and commission, this subclass of would contain an instance variable of baseSalary and would define the earnings method to return super. earnings() + baseSalary.
Each of these classes would contain a toString() method that displays the Compensation Model information as illustrated in the sample output.
This approach is more flexible than our original hierarchy. For example, consider an Employee who gets promoted. With the approach described here, you can simply change that Employee's CompensationModel by assigning the composed CompensationModel reference an appropriate subclass object. With the CommissionEmployee - hierarchy, you'd need to change the Employee's type by creating a new object of the appropriate class and moving data from the old object to the new one.
Implement the Employee class and CompensationModel hierarchy discussed in this exercise. In addition to the firstName, lastName, socialSecurityNumber and instance variables, class Employee should provide:
A constructor that receives three Strings and a to initialize the instance variables.
A set method that allows the client code to change an Employee's CompensationModel.
An earnings method that calls the CompensationModel's earning method and returns the result.
A toString() method that displays all the information about the Employee as illustrated in the sample output.
Your code in the subclasses should call methods in the super classes whenever possible to reduce the amount of code in the subclasses and utilize the code already developed in the super classes as in the code demonstrated in Figures 9.10 and 9.11 in the book.
Use the following code in your main function to test your classes, just copy and paste it into your main method:
// Create the two employees with their compensation models.
commissionModel = new (2000.00, 0.04);
basePlusCommissionModel = new (2000.00, 0.05, 600.00);
Employee employee1 = new Employee("John", "Smith", "111-11-1111", commissionModel);
Employee employee2 = new Employee("Sue", "Jones", "222-22-2222", basePlusCommissionModel);
System. out. printf("%s%n%s%n", employee1, employee2);
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 two employees.
commissionModelNew = new (5000.00, 0.04);
= new (4000.00, 0.05, 800.00);
// Set the new compensation models for the employees.
employee1.setCompensation();
employee2.setCompensation(commissio nModelNew);
// Print out the new information for the two employees.
System. out. printf("%s%n%s%n", employee1, employee2);
The output from your program should look like the following:
run:
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
Earnings for John Smith: 80.00
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

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 16:30
The most common battery cable terminal is a that provides a large surface contact area with the ability to tighten the terminal onto the battery post using a nut and bolt.
Answers: 2
question
Computers and Technology, 23.06.2019 11:00
What is the name of the sound effect that danny hears
Answers: 1
question
Computers and Technology, 24.06.2019 15:00
Universal windows platform is designed for which windows 10 version?
Answers: 1
question
Computers and Technology, 24.06.2019 23:00
Systolic pressure is a measure of blood pressure when the ventricles relax and fil with blood ture or false
Answers: 1
You know the right answer?
Assignment 2 - Employee Hierarchy In Chapter 9, we created the CommissionEmployee- inheritance hier...
Questions
question
Mathematics, 24.05.2021 09:40
question
Mathematics, 24.05.2021 09:50
question
History, 24.05.2021 09:50
question
History, 24.05.2021 09:50
question
History, 24.05.2021 09:50
question
History, 24.05.2021 09:50