Question: Use Java Write Payroll class that uses the following private arrays as fields employeeId An array of five integers to hold employee identification numbers hours
Use Java
Write Payroll class that uses the following private arrays as fields
employeeId An array of five integers to hold employee identification numbers
hours An array of five integers to hold the number of hours worked by each employee
payRate An array of five doubles to hold each employees hourly par rate
The class should relate the data in each array through the index/subscripts. Use appropriate set methods to initialize the array and get methods to return array.
The class should have method searchEmployee() that accepts an employees identification number as an argument and return the gross pay (Gross pay=hours*payRate) for that employee. Uses the sort and binarySearch method from the Arrays class to search the employee and return the gross pay for that employee.
The class should have method getHighest() method that find the highest pay rate of employee and return it.
Write Test class to create object of Payroll class and ask user to enter employee identification, hours worked and payRate of each employee. It should then display each employees identification number, hours, payRate and gross pay as per follows. Calculate gross pay=hours*payRate and store it in grossPay array.
Input validation: do not accept negative values for hours , numbers less than 6.00 for pay rate. Handle proper error If employee id does not match in searchEmployee() method
Following is sample run:
User loop to store following value in each array;
Enter emp id = 1 -> five different vale
Enter number of hours worked = 7 -> five different value
Enter employee hourly rate = 10.5 -> five different value
After storing value in each array print information as per follows:
empid hours payRate grosspay
1 7 10.5 73.5
2 8 20.5 164.0
3 9 30.5 274.5
4 5 40.5 202.5
5 6 50.5 303.0
Enter empid of employee which you want to calculate gross pay? 3
Gross pay of employee=274.5
Highest pay rate of employee=50.5
Or
Enter empid of employee which you want to calculate gross pay? 15
EmployeeId not present in array Index -6 out of bounds for length 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
