Question
The Employee Classes. Overview. In this challenge, you will modify the code of the payroll system presented in Figures 10.4 through 10.6. The updated version
The Employee Classes. Overview. In this challenge, you will modify the code of the payroll system presented in Figures 10.4 through 10.6. The updated version will still implement a loop to calculate the monthly payroll for each Employee. It will now include birthdate information for each employee, and each employee will receive a $100.00 bonus if the current payroll month is the employees birthdate month. Specifications Enter the original code shown in Figures 10.4 through 10.6 in your eBook text. Compile and run the code to ensure your entries are correct. Enter the Date class in Figure 8.7 and compile and run the code. Date Modify the Date class adding these methods: o getDay o getMonth o getYear o toString (to return a String of the form month/day/year) Employee and Its Subclasses Include private instance variable birthDate in class Employee. In the Employee constructor, use class Date to represent an employees birthday when assigning the value to birthDate. Add the method getBirthDate to the Employee class. In the subclasses of Employee (SalariedEmployee, HourlyEmployee, CommissionEmployee, and BasePlusCommissionEmployee), modify the constructors to include month, day, and year in the parameter list and in the call to the super class. PayrollSystemTest Create subclass objects with month, day, and year values passed to the constructor for each employee type. Create an array of Employee variables to store references to the various Employee objects. Declare a Scanner variable and a local variable currentMonth for keyboard entry of the payroll processing month. Add validation code to ensure an entry of 1 through 12 as the current month. Process the employees in a loop (polymorphically), and include code that determines each employees eligibility for the $100 bonus in the employees birthday month and adds that amount when applicable. Produce the example output shown below. Additional Requirements Follow the Basic Coding Standards.
// Fig. 10.4: Employee.java // Employee abstract superclass.
public abstract class Employee { private final String firstName; private final String lastName; private final String socialSecurityNumber;
//constructor public Employee(String firstName, String lastName, String socialSecurityNumber) { this.firstName = firstName; this.lastName = lastName; this.socialSecurityNumber = socialSecurityNumber; }
// return first name public String getFirstName() { return firstName; } //return last name public String getLastName() { return lastName; } //return social security number public String getSocialSecurityNumber() { return socialSecurityNumber; } //return String representation of Employee object @Override public String toString() { return String.format("%s %s%nsocial security number; %s", getFirstName(), getLastName(), getSocialSecurityNumber()): } //abstract method must be overridden by concrete subclasses public abstract double earnings(); // no implementation here // end abstract class Employee
//Fig. 10.5: SalariedEmployee.java //SalariedEmployee concrete class extends abstract class Employee.
public class SalariedEmployee extends Employee { private double weeklySalary; // constructor public SalariedEmployee(String firstName, String lastName, String socialSecurityNumber, double weeklySalary) { super(firstName, lastName, socialSecurityNumber); if (weeklySalary = 0.0"); this.weeklySalary = weeklySalary; } // set salary public void setWeeklySalary(double weeklySalary) { if(weeklySalary = 0.0"); this.weeklySalary = weeklySalary; } // return salary public double getWeeklySalary() { return weeklySalary; } // calculate earnings; override abstract method earnings in Employee @Override public double earnings() { return getWeeklySalary(); } // return String representation of SalarieEmployee object @Override public String toString() { return String.format("salaried employee: %s%n%s: $%,.2f", super.toString(), "weekly salary", getWeeklySalary()); } }// end class SalariedEmployee
// Fig. 10.6: HourlyEmployee.java // HourlyEmployee class extends Employee. public class HourlyEmployee extends Employee { private double wage; // wage per hour private double hours; // hours worked for week //constructor public HourlyEmployee(String firstName, String lastName, String socialSecurity, double wage, double hours) { super(firstName, lastName, socialSecurityNumber); if(wage = 0,0"); if((hours 168.0)) // validate throw new IllegalArgumentException( "Hours worked must be >= 0.0 and = 0.0"); this.wage = wage; } //return wage public double getWage() { return wage; } //set hours worked public void setHours(double hours) { if((hours 168.0)) // validate hours throw new IllegalArgumentException("Hours worked must be >= 0.0 and
Sample Output
Date object constructor for date 6/15/1944
Date object constructor for date 12/29/1960
Date object constructor for date 9/8/1954
Date object constructor for date 3/2/1965
Employees processed individually:
salaried employee: John Smith
social security number: 111-11-1111
birth date: 6/15/1944
weekly salary: $800.00
earned: $800.00
hourly employee: Karen Price
social security number: 222-22-2222
birth date: 12/29/1960
hourly wage: $16.75;
hours worked: 40.00
earned: $670.00
commission employee: Sue Jones
social security number: 333-33-3333
birth date: 9/8/1954
gross sales: $10,000.00;
commission rate: 0.06
earned: $600.00
base-salaried commission employee: Bob Lewis
social security number: 444-44-4444
birth date: 3/2/1965
gross sales: $5,000.00;
commission rate: 0.04;
base salary: $300.00
earned: $500.00
Enter the current month (1 - 12): 18
Enter the current month (1 - 12): 12
Employees processed polymorphically:
salaried employee: John Smith
social security number: 111-11-1111
birth date: 6/15/1944
weekly salary: $800.00
earned $800.00
hourly employee: Karen Price
social security number: 222-22-2222
birth date: 12/29/1960
hourly wage: $16.75; hours worked: 40.00
earned $670.00 plus $100.00 birthday bonus
commission employee: Sue Jones
social security number: 333-33-3333
birth date: 9/8/1954
gross sales: $10,000.00; commission rate: 0.06
earned $600.00
base-salaried commission employee: Bob Lewis
social security number: 444-44-4444
birth date: 3/2/1965
gross sales: $5,000.00; commission rate: 0.04; base salary: $300.00
new base salary with 10% increase is: $330.00
earned $530.00
Employee 0 is a SalariedEmployee
Employee 1 is a HourlyEmployee
Employee 2 is a CommissionEmployee
Employee 3 is a BasePlusCommissionEmployee
1 // Fig. 8.7: Date.java 2 Date class declaration. 4 public class Date private int month; / 1-12 private int day // 1-31 based on month private int year any year 10 private static final int[] daysPerMonth (0, 31, 28. 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 12 13 year 14 public Date (int month, int day, int year) 77 constructor: confirm proper value for month and day given the 16 17 18 19 20 21 77 check if month in range if (month 11 month > 12) throw new IllegalArgumentException( "month (onth ") must be 1-12") I/ check if day in range for month if (day0 I 23 24 25 26 (day> daysPerMonth [month] && ! (month2 && day 29)) throw new IllegalArgumentException ("day ("+ day + ") out-of-range for the specified month and year")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