Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i am looking for java. You will write a class named Employee that keeps track of

ID: 2246559 • Letter: I

Question

i am looking for java.

You will write a class named Employee that keeps track of the hours worked on each day of the week. The class will have the following members: a. hours - a double array with 7 elements. This holds the hours worked on each day of the week. Monday (index = 0) is the first day of the week. b. Employee - constructor that accepts a name for the employee and their pay rate (S/hr). c. getHours(i: int) - returns the number of hours worked on day i. d. setHours(i: int, num: double) - sets the number of hours worked on day e. get Name- returns the name f. getPayRate - returns the pay rate g. getNumDays Worked - returns the number of days worked. h. getTotalhours - returns the total number of hours worked for the week i. getWeekdayHours - returns the total number of hours worked during days (Mon-Fri) j. getWeekendHours - returns the total number of hours worked during the weekend (Sat-Sun) k. newWeek- starts the week over with no hours on any day. l. getPay - returns the total pay for the week computed in the following way: Weekday hours are paid at the pay rate. Any hours over 40 during weekdays are paid at time-and-a-half. Weekend hours are paid at double-time, no matter whether the workday hours exceeds 40. Working 7 consecutive day earns a bonus of $50.00, no matter how many total hours worked. m. mergeEmployee - accepts an Employee object and merges the hours. You can assume the input employee has the same name and pay rate. For example if e1 had hours: [8, 8, 8, 2, 0, 0, 0] and e2 had hours: [0, 0, 0, 4, 10, 0, 0]. Then, when is excecuted, the el will have hours: [8, 8, 8, 6, 10, 0, 0]. n. toString - returns a string that is formatted like this: Pay Stub, Name: Waldo, Pay Rate $25.00, Hours: Mon: 8.90 Tue: 8.00 Wed: 8.00 Thu: 8.00 Fri: 10.00 Sat: 2.00 Sun: 2.00 Days worked: 7 Total Hours: 46.00, Weekday hours: 42.00, Weekend hours: 4.00, Total pay: $1325.00

Explanation / Answer

Explanation::

Code in java::

import java.util.*;

class Employee{

/*

* hours array holds the hours worked on each day of the week,

* index 0 is for Monday and so on.

*/

double hours[]=new double[7];

/*

* employee name is stored in String variable named employeeName

* and payRate in double variable named payRate for each object.

*/

String employeeName;

double payRate;

Employee(String name,double newPayRate){

/*

* Constructor Employee sets name and pay rate of respective object

*/

employeeName=name;

payRate=newPayRate;

}

public double getHours(int i){

/*

* Day 1 is for Monday but its value is at index 0,

* so we need to use i-1 in return statement

*/

return hours[i-1];

}

public void setHours(int i,double num){

/*i=1 for Monday but index is i-1 */

hours[i-1]=num;

}

public String getName(){

/*Returns name of required object*/

return employeeName;

}

public double getPayRate(){

/*Returns payRate of required object*/

return payRate;

}

public int getNumDaysWorked(){

/*Function checks how many values in array hours[] is greater then 0*/

int workingDays=0;

for(int i=0;i<7;i++){

if(hours[i]>0){

workingDays++;

}

}

return workingDays;

}

public double getTotalHours(){

double totalHours=0;

for(int i=0;i<7;i++){

totalHours+=hours[i];

}

return totalHours;

}

public double getWeekdayHours(){

/*Returns sum of first 5 days of the week i.e from index i=0 to 4*/

double totalHours=0;

for(int i=0;i<5;i++){

totalHours+=hours[i];

}

return totalHours;

}

public double getWeekendHours(){

/*Returns Saturday and sunday hours addition at index i=5 and 6*/

return hours[5]+hours[6];

}

public void newWeek(){

/*Sets all values of hours[] to zero*/

for(int i=0;i<7;i++){

hours[i]=0;

}

}

public double getPay(){

/*Calculates total pay based on required parameters*/

double totalPay=0;

double weekDays=getWeekdayHours();

double weekendDays=getWeekendHours();

totalPay+=weekDays*payRate;

if(weekDays>40){

/*For all the hours after 40'th hour total pay gets extra payment for each hour */

double halfHours=weekDays-40;

totalPay+=halfHours*(payRate/2);

}

/*Weekends hours gives twice value of payRate*/

totalPay+=weekendDays*2*payRate;

if(getNumDaysWorked()==7){

totalPay+=50;

}

return totalPay;

}

public void mergeEmployee(Employee emp){

/*Merges two employees*/

for(int i=0;i<7;i++){

this.hours[i]+=emp.hours[i];

}

}

public String toString(){

/*For simplicity variables are created for each line in print format*/

String nameAndRate=String.format(" Name:"+getName()+", Pay Rate $%.2f",getPayRate());

String hoursStr=String.format(" Hours:Mon:%.2f Tue:%.2f Wed:%.2f Thu:%.2f Fri:%.2f Sat:%.2f Sun:%.2f",

hours[0],hours[1],hours[2],hours[3],hours[4],hours[5],hours[6]);

String dayHours=String.format(" Days worked:%d, Total Hours:%.2f",getNumDaysWorked(),getTotalHours());

String week=String.format(" Weekday hours:%.2f, Weekend hours: %.2f",getWeekdayHours(),getWeekendHours());

String totalPayStr=String.format(" Total pay: $%.2f",getPay());

return "Pay Stub. ----------"+nameAndRate+hoursStr+dayHours+week+totalPayStr;

}

public static void main(String args[]){

Employee e1=new Employee("Waldo",25);

Employee e2=new Employee("Sam",89.43);

/*Entering hours for employee e1 */

e1.setHours(1,8);

e1.setHours(2,8);

e1.setHours(3,8);

e1.setHours(4,8);

e1.setHours(5,10);

e1.setHours(6,2);

e1.setHours(7,2);

/*Printing e1*/

System.out.println(" Employee e1::");

System.out.println(e1);

/*Entering hours for employee e2 */

e2.setHours(1,6);

e2.setHours(2,5);

e2.setHours(3,5);

e2.setHours(4,3);

/*Printing e2*/

System.out.println(" Employee e2::");

System.out.println(e2);

/*Merging e1 and e2 into e1 and the printing e1 again*/

e1.mergeEmployee(e2);

System.out.println(" Employee e1 after merge::");

System.out.println(e1);

/*Setting e2 hours to newWeek and printing it*/

e2.newWeek();

System.out.println(" Employee e2 after newWeek::");

System.out.println(e2);

}

}

Output::


C:Algo>javac Employee.java

C:Algo>java Employee

Employee e1::
Pay Stub.
----------
Name:Waldo, Pay Rate $25.00
Hours:Mon:8.00 Tue:8.00 Wed:8.00 Thu:8.00 Fri:10.00 Sat:2.00 Sun:2.00
Days worked:7, Total Hours:46.00
Weekday hours:42.00, Weekend hours: 4.00
Total pay: $1325.00

Employee e2::
Pay Stub.
----------
Name:Sam, Pay Rate $89.43
Hours:Mon:6.00 Tue:5.00 Wed:5.00 Thu:3.00 Fri:0.00 Sat:0.00 Sun:0.00
Days worked:4, Total Hours:19.00
Weekday hours:19.00, Weekend hours: 0.00
Total pay: $1699.17

Employee e1 after merge::
Pay Stub.
----------
Name:Waldo, Pay Rate $25.00
Hours:Mon:14.00 Tue:13.00 Wed:13.00 Thu:11.00 Fri:10.00 Sat:2.00 Sun:2.00
Days worked:7, Total Hours:65.00
Weekday hours:61.00, Weekend hours: 4.00
Total pay: $2037.50

Employee e2 after newWeek::
Pay Stub.
----------
Name:Sam, Pay Rate $89.43
Hours:Mon:0.00 Tue:0.00 Wed:0.00 Thu:0.00 Fri:0.00 Sat:0.00 Sun:0.00
Days worked:0, Total Hours:0.00
Weekday hours:0.00, Weekend hours: 0.00
Total pay: $0.00

C:Algo>

Thank you!!