subject

(Recommended Project: Combining Composition and Inheritance) In this chapter, 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. Subclasses of CompensationModel would contain the details of a particular Employee’s compensation: —For Employees CompensationModel subclass would contain grossSales and commissionRate instance variables, and would define earnings to return grossSales * commissionRate. —For Employees who are paid a base salary and commission, this CompensationModel subclass would contain instance variables grossSales, commissionRate and baseSalary and would define earnings to return baseSalary + grossSales * commissionRate. Class Employee’s earnings method would simply call the composed CompensationModel’s earningsmethod and return its result. 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 into the new one. Implement the Employee class and CompensationModel hierarchy discussed in this exercise. In addition to the firstName, lastName, socialSecurityNumber and CompensationModel instance variables, class Employee should provide: A constructor that receives three Strings and a CompensationModel 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 earnings method and returns its result. When you invoke method earnings via the superclass CompensationModel reference to a subclass object (of type or ), you might expect superclass CompensationModel’s earnings method to execute. What actually happens? The subclass object’s earnings method executes. This is called polymorphic behavior, which we explore in Chapter 10. In your test application, create two Employee objects—one with a CommissionCompensation-Model and one with a —then display each Employee’s earnings. Next, change each Employee’s CompensationModel dynamically and redisplay each Employee’s earnings. In Chapter 10 ’s exercises, we’ll examine how to implement CompensationModel as an interface rather than a class.
Java language

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 09:30
Write a function called checkfactor that takes two arrays of positive numbers, firstnumberrow and secondnumberrow. checkfactor checks if the first entry in firstnumberrow is divisible by the first entry in secondnumberrow, and performs the same operation on the next array elements until all entries have been checked. all the numbers are positive and the number of entries in the arrays are the same. the function should return the identified divisible numbers in two row arrays named firstdivisible and seconddivisible.restrictions: branches or loops should not be used. the code must use the internal mod and logical functions.hint: the mod function should be used to determine if two numbers are divisible. ex: for num1 and num2 if mod(num1,num2) is 0, then the two numbers are divisible.this is matlab
Answers: 2
question
Computers and Technology, 24.06.2019 09:40
Healthy study habits are best described as
Answers: 1
question
Computers and Technology, 24.06.2019 13:30
In the rgb model, which color is formed by combining the constituent colors? a) black b) brown c) yellow d) white e) blue
Answers: 1
question
Computers and Technology, 24.06.2019 18:30
In what way is your social media footprint related to your digital id
Answers: 1
You know the right answer?
(Recommended Project: Combining Composition and Inheritance) In this chapter, we created the Commiss...
Questions
question
Biology, 21.10.2019 13:30
question
Mathematics, 21.10.2019 13:30
question
Mathematics, 21.10.2019 13:30
question
Mathematics, 21.10.2019 13:30
Questions on the website: 13722361