Overall Requirements: Tostring
Overall Requirements: Tostring
Overall Requirements
Write an employee payroll program that uses polymorphism to calculate and print the weekly
payroll for your company. There are three types of employees ─ hourly, salaried, and salaried
plus commission. Each type of employee gets paid using a different formula. But for all employee
types, if the calculated paycheck exceeds $1000, the actual paycheck must be decreased to
$1000.
Use the public access modifier for the toString method in the Employee class and the load
method in the Employee, Hourly, Salaried, and SalariedPlusCommission classes.
------------------------------------------------------
Employee.java class
Instance variables:
name
social security number
birthday month
birthday week
load method :
Prompts the user for instance-variable values and loads the entries.
toString method:
Returns a string that shows the employee’s name, social security number, and paycheck..
Use the String.format method (See Java API documentation to help you format the string as
shown in the sample session’s paycheck report.) Here’s an example from the sample session:
employee: Biff Sanchez
social security number: 111-11-1111
paycheck: $800.00
getBonus method:
Generates a $100 employee birthday bonus. Compare the employee’s birthday with the
current date found on your computer system. Use the Calendar class to generate the current
date. (See Sun’s Java API documentation.) If the employee’s birthday month and birthday
week match your computer system’s current month and current week, then increment the
employee’s paycheck by $100. The birthdayMonth holds the month (1─12) in which the
employee was born. The birthdayWeek holds the week (1─4) that the employee chooses to
get paid his/her bonus.
Use the public access modifier for the toString method to return a string version of the contents
of the employee.
------------------------------------------------------
Hourly.java class
Instance variables:
hourly pay
hours worked during the past week
load method:
Prompts the user for instance-variable values and loads the entries.
Include a getEarnings method that calculates earnings for an hourly employee. Hourly
employees are paid by the hour. If they work more than 40 hours in a week, then they receive
overtime pay for their overtime work. Overtime pay equals one and a half times their normal
hourly pay.
------------------------------------------------------
Salaried.java class
Instance variables:
Weekly salary
load method:
Prompts the user for instance-variable values and loads the entries.
Include a getEarnings method that calculates earnings for a salaried employee. Salaried
employees are paid their fixed weekly salary regardless of the number of hours they work.
------------------------------------------------------
SalariedPlusCommission.java class
Instance variables:
load method:
Prompts the user for instance-variable values and loads the entries.
Use initially declared named constants instead of hardcoded “magic numbers” embedded in the
program.
Number of employees: 3
PAYCHECK REPORT: