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 13:00
Which part of the cpu accepts data?
Answers: 1
question
Computers and Technology, 22.06.2019 15:20
The north and south regions had very diferent economies in the 1800s.
Answers: 1
question
Computers and Technology, 23.06.2019 01:30
In deadlock avoidance using banker’s algorithm, what would be the consequence(s) of: (i) a process declaring its maximum need as maximum possible for each resource. in other words, if a resource a has 5 instances, then each process declares its maximum need as 5. (ii) a process declaring its minimum needs as maximum needs. for example, a process may need 2-5 instances of resource a. but it declares its maximum need as 2.
Answers: 3
question
Computers and Technology, 23.06.2019 10:00
Hey i just logged on and one of the moderators deleted a bunch of my answers to questions, even though the answers were right and the people it doesn't make sense but if anyone wants to talk about anything just message me lol (this is super random lol)
Answers: 1
You know the right answer?
Assignment 2 - Employee Hierarchy In Chapter 9, we created the CommissionEmployee- inheritance hier...
Questions
question
Mathematics, 08.03.2021 04:10
question
Mathematics, 08.03.2021 04:10
question
Chemistry, 08.03.2021 04:10
question
Biology, 08.03.2021 04:10
Questions on the website: 13722360