can I get the code for this please Exercise 914 Employee Hie
can I get the code for this please
Exercise 9.14 Employee Hierarchy) In this chapter, you studied an inheritance hierarchy in which class BasePlusCommissionEmployee inherited from class CommissionEmployee. However, not all types of employees are CommissionEmployees. In this exercise, you\'ll create a more general Employee superclass that factors out the attributes and behaviors in class CommissionEmployee that are common to all Employees. The common attributes and behaviors for all Employees are fi rstName, l astName, socialSe-curityNumber, getFirstName, getLastName, getSocialSecurityNumber and a portion of method toString. Create a new superclass Employee that contains these instance variables and methods and a constructor. Next, rewrite class CommissionEmployee from Section 9.4.5 as a subclass of Employee. Class CommissionEmployee should contain only the instance variables and methods that are not declared in superclass Employee. Class CommissionEmployee\'s constructor should invoke class Employee\'s constructor and CommissionEmployee\'s toString method should invoke Employee\'s toString method. Once you\'ve completed these modifications, run the CommissionEmployeeTest and BasePlusCommis-sionEmployeeTest apps using these new classes to ensure that the apps still display the same results for a CommissionEmployee object and BasePlusCommissionEmployee object, respectively. Step-by-step solution Step 1 of 11 Program Plan for Testing CommissionEmployee class with Employee as Super class: • Create a class called Employee. • Declare three instance variables firstName, lastName and socialSecurityNumber. • Write getter methods for instance variables of Employee class. • Override the toString method of Employee class. • The toString method returns the string representation of Employee. • Modify the class CommissionEmployee class that extends the class Employee • Call the super class constructor Employee with three arguments. • Remove the instance variable for Employee from the class • CommissionEmployee. • Modify the toString method that calls the Employee class toString method and add gross sales and commission rate values. • Create a class called CommissionEmployeeTest. • Test the class with new changes in the class CommissionEmployee and Employee class. • Check whether the same results obtained even if the CommissionEmployee class is modified and add a new class Employee is set as super class for CommissionEmployee class.
Solution
Actually you have either incorrectly copy paste the question or have partially done it as it require basePlusCommisonEmployeeTest class. Anyway as far as I understand it wants you to test two cases-
1) CommisionEmployee class will contains all the variable and we just have to print it using toString() method
2) CommisioEmployee class will not contain three variable i.e. firstName, lastName, SSN and you need to override class Employee to use these variable and then print it again toString() and compare if two result are same or not.
So yes both result will be same and I will do it for you
first I will make second case then first one ok.The test class for this problem is CommisionEmployeeTest1.
Make separate file otherwise remove public from all except CommissionEmployeeTest1
Employee.java
CommissionEmployee.java
CommissionEmployeeTest1.java
output is
CommisionEmployee{firstName=\'harry\', lastName=\'potter\', socialSecurityNumber=979999999grossSales=12218.232, commissionRate=32.213}
CommisionEmployee{firstName=\'Alex\', lastName=\'george\', socialSecurityNumber=972329999grossSales=1221998.12, commissionRate=47.223}
2)
Now for the first case where there is no employee class and all variable is declared in CommissionEmployee class.
Test class for this class is CommissionEmployeeTest2.java
CommisionEmployee.java
CommissionEmployeeTest2.java
Output-
CommisionEmployee{firstName=\'harry\', lastName=\'potter\', socialSecurityNumber=979999999, grossSales=12218.232, commissionRate=32.213}
CommisionEmployee{firstName=\'Alex\', lastName=\'george\', socialSecurityNumber=972329999, grossSales=1221998.12, commissionRate=47.223}
I think there is no need for comment in this code. Its basic of Inheritance and you can understand easily by seeing the code. But anyhow if you don\'t understand any part of it please ask me. And try to experiment with the class by adding some variable and adding that in toString() method. There might be some formatting issue in toString() method but data it will print will always be same.

