The computations are as follows: If an employee works more than 6 hours then ded
ID: 3816807 • Letter: T
Question
The computations are as follows: If an employee works more than 6 hours then deduct 1 hour for a lunch period. If an employee, after deducting 1 hour works more than 8 hours in a day then the hours in excess of the 8 are considered to be overtime. Any hours in excess of 40 overtime hours are also considered overtime. non The normal hours worked will the total of all the non-overtime hours. This cannot be more than 40 hours. overtime hours worked will be the total of all hours considered to be overtime. The Normal pay will be the normal hours worked times the hourly wage. overtime pay will be the normal hours worked times the hourly wage times 1 Gross pay is the sum ofnormal pay and overtime pay. Federal tax is 10% of the gross pay in excess of S500.00. State tax is 3% of the gross pay. Net pay is gross pay less federal and state taxes. The end of the pay period will be 6 days after the start of the pay period. The date of the pay check will be 13 days after the start of the pay period. Additional Specifications: You will need 3 classes to represent the business objects for this problem, one for the employee, one for the pay stub (which includes code to print both the pay report and pay check), and one for daily time entry. Note that for the pay stub, there can be many time entries. Provide ter methods for all instance variables. The only setter methods will employee's pay rate (yes they can get a raise). You do not need to write a program that accepts user input. Like assignments 1 and 2, just write a test program (this will be a fourth class). Is should instantiate a sufficient set of objects to print pay reports and pay checks for 3 different employees. The test program can hard code the data which is passed to the constructors. (do not hard code other values in the business classes except for federal tax rate, state tax rate, federal tax exemption 500, 1 hour lunch deduction, 8 hour daily overtime threshold, and 40 hour weekly threshold). Make sure you develop test cases of an employee that receives noExplanation / Answer
package timesheet;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Employee {
private static int PAY_DAYS = 6;
private String employeeId;
private String employeeName;
private LocalDate startDate;
private Map<LocalDate,Timesheet> ts = new HashMap<LocalDate,Timesheet>();
public Map<LocalDate, Timesheet> getTs() {
return ts;
}
public Employee(String empId, String empName, LocalDate date)
{
employeeId = empId;
employeeName = empName;
startDate = date;
}
public String getEmployeeId() {
return employeeId;
}
public void setEmployeeId(String employeeId) {
this.employeeId = employeeId;
}
public String getEmployeeName() {
return employeeName;
}
public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}
public LocalDate getStartDate() {
return startDate;
}
public void setStartDate(LocalDate startDate) {
this.startDate = startDate;
}
public void addTimesheetEntry(LocalDate date,LocalTime inTime, LocalTime outTime)
{
Timesheet ts1 = new Timesheet(inTime,outTime);
ts.put(date,ts1);
}
}
package timesheet;
import java.time.LocalDate;
import java.time.LocalTime;
public class Timesheet {
private LocalTime inTime;
private LocalTime outTime;
public Timesheet(LocalTime inTime2, LocalTime outTime2)
{
inTime = inTime2;
outTime = outTime2;
}
public LocalTime getInTime() {
return inTime;
}
public void setInTime(LocalTime inTime) {
this.inTime = inTime;
}
public LocalTime getOutTime() {
return outTime;
}
public void setOutTime(LocalTime outTime) {
this.outTime = outTime;
}
}
package timesheet;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class PayStub {
private static int federalTax = 10;
private static int stateTax = 3;
private double payRate;
public void setPayRate(double payRate) {
this.payRate = payRate;
}
private double normalPay;
private double grossPay;
private double overTimePay;
private double netPay;
private List<Integer> workHours = new ArrayList<Integer>();
private List<Integer> overtimeHours = new ArrayList<Integer>();
private int totalNormalHours = 0;
private int totalovertimeHours = 0;
private double stateTaxTotal =0;
private double federalTaxToal = 0;
private Employee emp;
public PayStub(Employee e) {
emp = e;
}
public void printReport()
{
calculateHours();
calculatePay();
System.out.println("Employee No.: " + emp.getEmployeeId());
System.out.println("Employee Name: " + emp.getEmployeeName());
System.out.println("Pay Period: " + emp.getStartDate() + " to "+ emp.getStartDate().plusDays(6) );
System.out.println(" Normal Hours Worked: " + totalNormalHours);
System.out.println("Overtime Hours Worked: " + totalovertimeHours);
System.out.println("Hourly wage: " +payRate);
System.out.println(" ");
System.out.println("Normal Pay: $"+normalPay);
System.out.println("OverTime Pay: $"+overTimePay);
System.out.println("Gross Pay: $"+grossPay);
System.out.println("Federal Tax: $"+federalTax);
System.out.println("State Tax: $"+stateTax);
System.out.println("Net Pay: $"+netPay);
System.out.println(" Time Log ");
System.out.println(" Date In Out Hours OT Hours");
int i = 0;
Map<LocalDate,Timesheet> mapTs = emp.getTs();
for(LocalDate date: mapTs.keySet())
{
System.out.println(date.toString()+ " " + mapTs.get(date).getInTime() + " " + mapTs.get(date).getInTime() + workHours.get(i) + overtimeHours.get(i));
i++;
}
}
private void calculatePay() {
normalPay = totalNormalHours * payRate;
overTimePay = totalovertimeHours * payRate * 1.5;
grossPay = normalPay + overTimePay;
stateTaxTotal = 0.03 *grossPay;
federalTaxToal = 0;
if(grossPay > 500)
{
federalTaxToal = .10 * grossPay;
}
netPay = grossPay - (federalTax + stateTax);
}
private void calculateHours() {
Map<LocalDate,Timesheet> mapTs = emp.getTs();
for(LocalDate date: mapTs.keySet())
{
Timesheet t = mapTs.get(date);
int hours = (int) ChronoUnit.HOURS.between(t.getOutTime(), t.getInTime()) ;
if(hours >= 6 && hours <= 8)
{
//subtract one hr for lunch
workHours.add(hours - 1);
}
else if((hours - 1) >= 8)
{
workHours.add(hours - 1);
overtimeHours.add(hours - 9);
}
else
workHours.add(0);
}
for(int hr: workHours)
{
totalNormalHours += hr;
}
for(int hr1: overtimeHours)
{
totalovertimeHours += hr1;
}
}
public void printPayCheck() {
System.out.println("Pay Check: " + emp.getStartDate().plusDays(13) );
System.out.println(" Pay to: " + emp.getEmployeeName() +" $" + netPay);
}
}
package timesheet;
import java.time.LocalDate;
import java.time.LocalTime;
public class TimesheetTest {
public static void main(String[] args) {
LocalDate date = LocalDate.now();
Employee e = new Employee("20313", "XYZZZZZZZ ABCCCC",date);
LocalTime t1 = LocalTime.now();
e.addTimesheetEntry(date, t1, t1.plusHours(8));
t1 = LocalTime.now().plusHours(1);
e.addTimesheetEntry(date.plusDays(1), t1, t1.plusHours(10));
PayStub report = new PayStub(e);
report.printReport();
report.printPayCheck();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.