Question
Class Diagram: Create a class diagram that models the relationship of the classes that you created for Assignment 2. Include 4 classes with their attributes
Class Diagram: Create a class diagram that models the relationship of the classes that you created for Assignment 2. Include 4 classes with their attributes and behaviors in the diagram.
Please use the description/instruction of assignment 2 below to create the above class diagram.
Assignment 2:
ASSIGNMENT 2 COMBINING COMPOSITION AND INHERITANCE
In this module, 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.
Employee, has a CompensationModel --- Create classes Employee and CompensationModel.
A CompensationModel would provide an earnings method. (This could only return 0.0, since it will be overridden in subclasses.)
Subclasses of CompensationModel would contain the details of a particular Employees compensation:
CommissionCompensationModel --- For Employees who are paid by commission, this CompensationModel sublass would contain variables, and would define .
BasePlusCompensationModel --- For Employees who are paid a base salary and commission, this CompensationModel subclass would contain instance variables
and would define earnings to return (Do not forget to write parameterized constructors and set and get methods of the subclasses.)
Class Employees earnings method would simply call the composed CompensationModels earnings method 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 employees CompensationModel by assigning the composed CompensationModel reference an appropriate subclass object. With the CommissionEmployee BasePlusCommissionEmployee hierarchy, youd need to change employees type by creating a new object of appropriate class and moving data from the old object into the new one.
grossSales, commissionRate, and baseSalary
grossSales andcommissionRate instance
earnings to return grossSales * commissionRate
baseSalary + grossSales * commissionRate.
INSTRUCTIONS
Implement the Employee class and CompensationModel hierarchy disucssed 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 Employees CompensationModel.
An earnings method that calls the CompensationModels earnings method and
returns its result.
When you invoke method earnings via the superclass CompensationModel reference to a subclass object (of type CommissionCompensationModel or BasePlusCoimmissionCompensationModel), you might expect superclass CompensationModels earnings method to execute. What actually happens? The subclass objects earnings method executes. This is called polymorphic behavior, which we explore in the next module.
In your Test application, create two Employee objects:
one with a CommissionCompensationModel
and one with a BasePlusCommissionCompensationModel
then display each Employees earnings.
Next, change each Employees CompensationModel dynamically
and redisplay each Employees earnings.
In the next modules exercises, well examine how to implement CompensationModel as an interface rather than a class.
After completing the assignment submit 5 java files that are Test, Employee, CompensationModel, ComissionCompensationModel, and BasePlusCommissionCompensationModel.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started