Question: Language: Java Here is one version of the CommissionEmployee class : public class CommissionEmployee extends Object { private final String firstName; private final String lastName;

Language: Java

Here is one version of the CommissionEmployee class : public class CommissionEmployee extends Object { private final String firstName; private final String lastName; private final String socialSecurityNumber; private double grossSales; private double commissionRate; public CommissionEmployee(String firstName, String lastName, String socialSecurityNumber, double grossSales, double commissionRate) { if (grossSales < 0.0) throw new IllegalArgumentException( "Gross sales must be >= 0.0"); if (commissionRate <= 0.0 || commissionRate >= 1.0) throw new IllegalArgumentException( "Commission rate must be > 0.0 and < 1.0"); this.firstName = firstName; this.lastName = lastName; this.socialSecurityNumber = socialSecurityNumber; this.grossSales = grossSales; this.commissionRate = commissionRate; } public String getFirstName() {return firstName;} public String getLastName() {return lastName;} public String getSocialSecurityNumber() {return socialSecurityNumber;} public void setGrossSales(double grossSales) { if (grossSales < 0.0) throw new IllegalArgumentException( "Gross sales must be >= 0.0"); this.grossSales = grossSales; } public double getGrossSales() {return grossSales;} public void setCommissionRate(double commissionRate) { if (commissionRate <= 0.0 || commissionRate >= 1.0) throw new IllegalArgumentException( "Commission rate must be > 0.0 and < 1.0"); this.commissionRate = commissionRate; } public double getCommissionRate() {return commissionRate;} public double earnings() {return commissionRate * grossSales;} @Override public String toString() { return String .format("%s: %s %s%n%s: %s%n%s: %.2f%n%s: %.2f", "commission employee", firstName, lastName, "social security number", socialSecurityNumber, "gross sales", grossSales, "commission rate", commissionRate); } } However, it's important to note that not all employees are CommissionEmployees. Create a more general Employee superclass that factors out the attributes and behaviors in CommissionEmployees that are common to all Employees. The common attributes and behaviors for all Employees are firstName, lastName, socialSecurityNumber, getFirstName, getLastName, getSocialSecurityNumber, and a portion of the method toString. Create a new superclass Employee that contains these instance variables and methods and a constructor . Next, rewrite the CommissionEmployee class as a subclass of Employee. CommissionEmployee should contain only the instance variables and methods that are not declared in superclass Employee. CommissionEmployee's constructor should invoke Employee's constructor and CommissionEmployee's toString method should invoke Employee's toString method . Create a Driver class to test your new CommissionEmployee class . Prompt the user to input the first name , last name , social security number, gross sales, and commission rate and create a CommissionEmployee object , using the toString method to print its information.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!