Can someone please write it out clearly in Java, much appreciated! A company pay
ID: 3803411 • Letter: C
Question
Can someone please write it out clearly in Java, much appreciated!
A company pays its employees on a weekly basis. The company has three types of employees:
Salaried employees, who are paid a fixed weekly salary regardless of the number of hours worked;
Hourly employees, who are paid by the hour and receive overtime pay;
Commissioned employees whose pays are 20% of the week's sales
Create a console-based Java application that:
Calculates weekly pay for an employee. The application should display text that requests the user input the name of the employee, type of employee, and the monthly salary, or hourly rate, if it’s an hourly employee, and hours worked for the week.
For hourly employees, the rate will be doubled if it’s beyond 40 hours/week.
The application should then print out the name of the employee and the weekly pay amount. In the printout, display the dollar symbol ($) to the left of the weekly pay amount and format the weekly pay amount to display currency.
Implements a feature that allows the company to reward selected salaried employees by adding 10% to their salaries. Your program should display an asterisk (*) to the upper right of the weekly pay amount, and a note stating bonus added below the table, as shown below:
Name Class Hours Sales Rate Weekly Pay Amount
===========================================================
James Hogan Salaried $3,300.00*
Jennifer Waltz Hourly 45 $10.95 $547.50
Moly Smith Hourly 32 $15.00 $480.00
Joan Han Salaried $2,600.00
Marry Butler Commissioned $10,000.00 $2,000.00
===========================================================
TOTAL $8,827.50
*A 10% bonus is awarded
Explanation / Answer
public class HourlyEmployee extends Employee
{
private double wage; // wage per hour
private double hours; // hours worked for week
public HourlyEmployee( String first, String last, String ssn,
double hourlyWage, double hoursWorked )
{
super( first, last, ssn );
setWage( hourlyWage );
setHours( hoursWorked );
}
public void setWage( double hourlyWage )
{
if ( hourlyWage >= 0.0 )
wage = hourlyWage;
else
throw new IllegalArgumentException(
"Hourly wage must be >= 0.0" );
}
public double getWage()
{
return wage;
}
public void setHours( double hoursWorked )
{
if ( ( hoursWorked >= 0.0 ) && ( hoursWorked <= 168.0 ) )
hours = hoursWorked;
else
throw new IllegalArgumentException(
"Hours worked must be >= 0.0 and <= 168.0" );
public double getHours()
{
return hours;
}
@Override
public double earnings()
{
if ( getHours() <= 40 ) // no overtime
return getWage() * getHours();
else
return 40 * getWage() + ( getHours() - 40 ) * getWage() * 1.5 ;
}
@Override
public String toString()
{
return String.format( "hourly employee: %s %s: $%,.2f; %s: %,.2f",
super.toString(), "hourly wage" , getWage(),
"hours worked", getHours() );
}
}