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

hours : int payRate: doublel + setHours(element: int, hrs: int): void +setPayRat

ID: 3697218 • Letter: H

Question





hours : int payRate: doublel + setHours(element: int, hrs: int): void +setPayRate(element: int, rate: double):void +getEmployeeld: int): int + getGrossPay(element: int): double o employeeld. An array of five (5) integers to hold employee identification numbers. The array should be initialized with the following numbers 5658845 4520125 7895122 8777541 8451277 o hours. An array of five (5) integers to hold the number of hours worked by each employee o payRate. An array of five (5) doubles to hold each employees hourly pay rate You must have two (2) classes, the Payroll class containing all accessor and mutator methods and the PayrollApp class containing the main method. The Payroll class should relate the data in each array through the subscripts. For example, the number in element 0 of the hours array should be the number of hours worked by the employee whose identification number is stored in element 0 of the employeeld array. The same employee's pay rate should be stored in element 0 of the payRate array. Demonstrate the class in a complete program that displays each employee number and asks the user to enter that employee's hours and pay rate. It should then display each employee's identification number and gross wages formatted using the printf method. See sample run below Enter the hours worked by employee 5658845: 45 Enter the pay rate for employee 5658845: 22.50 Enter the hours worked by employee 4520125: 55 Enter the pay rate for employee 4520125: 21.25 Enter the hours worked by employee 7895122: 33 Enter the pay rate for employee 7895122: 17.25 Enter the hours worked by employee 8777541: 25 Enter the pay rate for employee 8777541: 16.35 Enter the hours worked by employee 8451277: 15 Enter the pay rate for employee 8451277: 12.10 The total wage for employee 5658845 is $1,012.50 The total wage for employee 4520125 is $1,168.75 The total wage for employee 7895122 is $569.25 The total wage for employee 8777541 is $408.75 The total wage for emplovee 8451277 is S181.50

Explanation / Answer

import java.io.*;
import java.util.Scanner;
public class PayRoll{
public static void main(String []args){
//Employee Id are taken into an array   
int EmpID[]={5658845,4520125,7895122,8777541,8451277};
int i;
//Hours and pay salary array
int[] hours = new int[5];
double[] pay = new double[5];
Scanner sc=new Scanner(System.in);
//Entering the hours and pay for each employee
for(i=0;i<5;i++){
System.out.println("Enter the hours worked by employee "+i+":");
hours[i]=sc.nextInt();
//Checking whether valid value of hours is given
if(hours[i] <= 0){
do{
System.out.println("Please enter a number above 0:");
hours[i]=sc.nextInt();
}while(hours[i] <= 0);
}
System.out.println("Enter the pay rate for employee "+i+":");
pay[i]=sc.nextDouble();
if(pay[i] <= 6.0){
do{
System.out.println("Please enter a rate above 6:");
pay[i]=sc.nextDouble();
}while(hours[i] <= 6.0);
}
}
double result;
//Caluclating the total wage of each employee
for(i=0;i<5;i++){
result = hours[i] * pay[i];
System.out.println("The total wage for employee "+i+" is $"+result);
}
int Id;
System.out.println("Enter an employee number: ");
Id=sc.nextInt();
  for(int i=0;i<5;i++){
      if(EmpId[i]!= Id){
         do{
System.out.println("That is not a valid employee id number,please try again :");
         Id=sc.nextInt();
}while(Id==EmpID[i])
      }
      else{
      result = hours[i] * pay[i];
System.out.println("The total wage for employee "+i+" is $"+result);
      }
}
}

Hope this code is helpful and meet all the additional functionalities mentioned.