Question: NEED HELP WRITING A JAVA PROGRAM In Chapter 9, we studied an inheritance hierarchy in which class BasePlusCommissionEmployee inherited from CommissionEmployee. However, not all employees

NEED HELP WRITING A JAVA PROGRAM

In Chapter 9, we studied an inheritance hierarchy in which class BasePlusCommissionEmployee inherited from CommissionEmployee. However, not all employees are CommissionedEmployees. For this assignment, create a more general Employee class that factors out the attributes and behavior that are common to all employees. Also, you will add two new types of employees, a SalariedEmployee, who gets paid a fixed salary, and an HourlyEmployee who gets paid an hourly wage plus time-and-a-half (1.5 times their hourly wage for hours worked over 40 hours). Create the proper Employee class hierarchy to reflect good object-oriented design.

The SalariedEmployee will need the additional instance variable of salary, and the HourlyEmployee will need the additional instance variables of hourlyWage and hoursWorked. Add setters and getters for these classes as appropriate. These classes will also need the earnings method and an override for the toString() method. The SalariedEmployee class will need a setSalary method to set the current salary for the employee. The HourlyEmployee class will need set methods for the hourlyWage and hoursWorked variables also. Salary and hourlyWage should be checked to make sure they are greater than zero and hoursWorked should be checked to ensure that it is between 1 and 168 (the number of hours in a week).

Your code in the subclasses should call methods in the super classes whenever possible to reduce the amount of code in the subclasses and utilize the code already developed in the super classes as in the code demonstrated in Figures 9.10 and 9.11 in the book.

Use the following code in your main function to test your classes:

CommissionEmployee employee1 = new CommissionEmployee("Fred", "Jones", "111-11-1111", 2000.0, .05); BasePlusCommissionEmployee employee2 = new BasePlusCommissionEmployee("Sue", "Smith", "222-22-2222", 3000.0, .05, 300); SalariedEmployee employee3 = new SalariedEmployee("Sha", "Yang", "333-33-3333", 1150.0); HourlyEmployee employee4 = new HourlyEmployee("Ian", "Tanning", "444-44-4444", 15.0, 50); HourlyEmployee employee5 = new HourlyEmployee("Angela", "Domchek", "555-55-5555", 20.0, 40); System.out.printf("%s%s%s%s%s", employee1, employee2, employee3, employee4, employee5);

The output from your program should look like the following:

run: Commissioned Employee: Fred Jones with ssn: 111-11-1111 Gross Sales: 2000.00 Commission Rate: 0.05 Earnings: $100.00 Base Salary Plus Commissioned Employee: Sue Smith with ssn: 222-22-2222 Gross Sales: 3000.00 Commission Rate: 0.05 with Base Salary of: $300.00 Earnings: $450.00 Salaried Employee: Sha Yang with ssn: 333-33-3333 Salary: 1150.00 Earnings: $1150.00 Hourly Employee: Ian Tanning with ssn: 444-44-4444 Hourly Wage: 15.00 Hours Worked: 50.00 Earnings: $825.00 Hourly Employee: Angela Domchek with ssn: 555-55-5555 Hourly Wage: 20.00 Hours Worked: 40.00 Earnings: $800.00 public class Employees { private final String firstName; private final String lastName; private final String socialSecurityNumber; private double grossSales; private double commissionRate; //five-argument constructor public Employees(String firstName, String lastName,String socialSecurityNumber , double grossSales,double commissionRate) { //implicit call to Object constructor occurs here //if grossSales is invalid throw exception if(grossSales<0.0) throw new IllegalArgumentException( "Gross sales must be >=0.0"); //if commssionRate is invalid throw exception 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; }// end Constructors //return first name public String getFirstName() { return firstName; } //return last name public String getLastName() { return lastName; } //return Social Secrutiy Number public String getSocialSecurityNumber() { return socialSecurityNumber; } //set gross sales amount public void setGrossSales(double grossSales) { if(grossSales<0.0) throw new IllegalArgumentException( "Gross sales must be >=0.0"); this.grossSales=grossSales; } //return gross sales amount public double getGrossSales() { return grossSales; } //set commission rate 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; } //return commission rate public double getCommissionRate() { return commissionRate; } //calculate earnings public double earnings() { return getCommissionRate()*getGrossSales(); } //return String represntation of Commission Employee object @Override public String toString() { return String.format("%s: %s %s%n%s: %s%n%s: %.2f%n%s: %.2f", "commission employee", getFirstName(), getLastName(), "social security number", getSocialSecurityNumber(), "gross sales",getGrossSales(), "commission rate", getCommissionRate()); }//end class Comission Employee //BaseplusCommissionEmployee public class BasePlusCommissionEmployee extends Employees { private double baseSalary; // base salary oer week //six-argument constructor public BasePlusCommissionEmployee(String firstName,String lastName, String socialSecurityNumber, double grossSales, double commissionRate, double baseSalary) { super(firstName, lastName, socialSecurityNumber, grossSales, commissionRate); //if baseSalary is invalid throw exception if(baseSalary<0.0) throw new IllegalArgumentException( "Base salary must be 0.0"); this.baseSalary=baseSalary; } // set base salary public void setBaseSalary(double baseSalary) { if (baseSalary <0.0) throw new IllegalArgumentException( "Base salary must be >-0.0"); this.baseSalary=baseSalary; } //return base salary public double getBaseSalary() { return baseSalary; } //calcualte earnings @Override public double earnings() { return getBaseSalary()+super.earnings(); } //return String representation of Base Plus Commission Employee @Override public String toString() { return String.format("%s %s%n%s %.2f","base-salaried", super.toString(),"base salary", getBaseSalary()); } }//end class BasePlusCommissionEmployee

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!