The file must be called <Payroll.java> (driver program) Employee.java Hourly.jav
ID: 3558994 • Letter: T
Question
The file must be called <Payroll.java> (driver program)
Employee.java
Hourly.java (which extends employee)
Salaried.java (which extends employee)
SalariedPlusCommission.java (which extends Salaried)
Ensure you include ALL files required to make your program compile and run.
I would like to see your .java files only.
Proper coding conventions required the first letter of the class start with a capital
letter and the first letter of each additional word start with a capital letter.
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 this class hierarchy:
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.
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
Explanation / Answer
Employee.java
package chegg;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
public abstract class Employee {
private String name;
private String socialSecurityNumber;
private int birthdayMonth;
private int birthdayWeek;
@SuppressWarnings("resource")
public Employee() {
Scanner input = new Scanner(System.in);
System.out.println("Please Enter Name of the Employee: ");
this.name = input.next();
System.out.println("Please Enter Social Security of the Employee: ");
this.socialSecurityNumber = input.next();
System.out
.println("Please Enter Birthday Month of the Employee(1 - 12): ");
this.birthdayMonth = input.nextInt();
System.out
.println("Please Enter Birthday Week of the Employee(1 - 4): ");
this.birthdayWeek = input.nextInt();
}
@Override
public String toString() {
return "PAYCHECK REPORT: " + "employee: " + name + " "
+ "social security number: " + socialSecurityNumber + " "
+ "paycheck: " + (getEarnings() + getBonus()) + " ";
}
public abstract double getEarnings();
public int getBonus() {
Calendar cal = Calendar.getInstance();
Date date = new Date();
cal.setTime(date);
int getCurrentMonth = cal.get(Calendar.MONTH);
// As per assumption
getCurrentMonth = 10;
int getCurrentWeek = cal.get(Calendar.DAY_OF_WEEK_IN_MONTH);
// As per assumption
getCurrentWeek = 2;
if (getCurrentMonth == birthdayMonth && getCurrentWeek == birthdayWeek)
return 100;
return 0;
}
}
Hourly.java
package chegg;
import java.util.Scanner;
public class Hourly extends Employee {
private int hourlyPay;
private int hoursWorkedPastWeek;
@SuppressWarnings("resource")
public Hourly() {
Scanner input = new Scanner(System.in);
System.out.println("Please Enter Hourly Pay of the Employee: ");
this.hourlyPay = input.nextInt();
System.out
.println("Please Enter Hours Worked Past Week by the Employee: ");
this.hoursWorkedPastWeek = input.nextInt();
}
@Override
public double getEarnings() {
int weeklyIncome = hourlyPay * hoursWorkedPastWeek;
if (hoursWorkedPastWeek > 40) {
return weeklyIncome * 1.5;
}
return weeklyIncome;
}
}
Salaried.java
package chegg;
import java.util.Scanner;
public class Salaried extends Employee {
private int weeklySalary;
@SuppressWarnings("resource")
public Salaried() {
Scanner input = new Scanner(System.in);
System.out.println("Please Enter Salary of the Salaried Employee: ");
this.weeklySalary = input.nextInt();
}
@Override
public double getEarnings() {
return weeklySalary;
}
}
SalariedPlusCommission.java
package chegg;
import java.util.Scanner;
public class SalariedPlusCommission extends Salaried {
private int salesDuringPastWeek;
private double commissionRate;
@SuppressWarnings("resource")
public SalariedPlusCommission() {
Scanner input = new Scanner(System.in);
System.out
.println("Please Enter Sales During Past Week of Salaried Employee: ");
this.salesDuringPastWeek = input.nextInt();
System.out
.println("Please Enter Commission Rate of Salaried Employee: ");
this.commissionRate = input.nextDouble();
}
@Override
public double getEarnings() {
return super.getEarnings() + salesDuringPastWeek * commissionRate;
}
}
PayRoll.java
package chegg;
import java.util.Scanner;
public class PayRoll {
@SuppressWarnings("resource")
public static void main(String arg[]) {
Scanner input = new Scanner(System.in);
System.out.println("Please Enter the number of Employees: ");
int numOfEmployees = input.nextInt();
for (int employeeCount = 0; employeeCount < numOfEmployees; employeeCount++) {
System.out.println("PROFILE FOR EMPLOYEE #" + (employeeCount + 1));
System.out
.println("type Hourly(1), Salaried(2), Salaried plus Commission(3)");
System.out.print("Enter 1, 2, or 3 ==> ");
int employeeType = input.nextInt();
switch (employeeType) {
case 1:
Hourly hourlyEmployee = new Hourly();
System.out.println(hourlyEmployee);
break;
case 2:
Salaried salariedEmployee = new Salaried();
System.out.println(salariedEmployee);
break;
case 3:
SalariedPlusCommission salariedPlusCommissionEmployee = new SalariedPlusCommission();
System.out.println(salariedPlusCommissionEmployee);
break;
default:
System.out.println("JUNK VALUE TRY 1 or 2 or 3");
break;
}
}
}
}
Note : change month and week to calender method after testing the sample
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.