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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 08:10, autumnguidry1622
Technician a says that if a valve is open when a piston rises to the very top of a cylinder, the piston may actually strike the valve head and cause serious engine damage. technician b says if the camshaft is located in the engine block, then the engine is called an overhead valve engine, ohv engine, or an in-block camshaft. who is right? a. b only b. both a and b c. a only d. neither a nor b
Answers: 3
image
Computers and Technology, 23.06.2019 07:30, barkonatree
What is the penalty for violating section 1201 of title 17 chapter 21 of the us code
Answers: 1
image
Computers and Technology, 23.06.2019 09:00, vetterk1400
Design a class tictactoe that: holds the following information about the game: two-dimensional array (3 by 3), and winner. add additional variables as needed. includes the functions to perform the various operations on objects. for example, function to print the board, getting the move, checking if move is valid, determining if there is a winner after each move. add additional operations as needed. includes constructor(s). write the functions of the class, and write a program that uses the class. the program should declare an object of type tictactoe. the program will create the board and store it in the array. the program will allow two players to play the tic-tac-toe game. after every valid move update the array, check if there is a winner. if there is no winner and no tie, then print the board again to continue.
Answers: 2
image
Computers and Technology, 23.06.2019 09:10, djs1671
(328 inc. 448 ind. 480 in25. john has a collection of toy cars. he has 2 red cars, 4 blue cars, 4 black cars, and 6 yellowcars. what is the ratio of red cars to yellow cars? a. 1: 2b. 1: 3c. 1: 626. the net of a right triangular prism is shown below.
Answers: 2
You know the right answer?
(Recommended Project: Combining Composition and Inheritance) In this chapter, we created the Commiss...

Questions in other subjects:

Konu
Mathematics, 11.10.2019 20:30
Konu
Social Studies, 11.10.2019 20:30