Use two methods that work with arrays that contain the payroll data. The first method, which will be called getPayrollData(), will be called from main() in order to get the payroll data from the user. It must do the following:
Prompt the user for the number of employees to be processed.
Create an array of the size needed to hold the hours worked for this many employees. This should be an array of int since the company requires that full hours be worked.
Input the hours worked into the array using a loop and identifying employees as described further down.
Pass the array back to main() as the return value of the method.
You will create a second method called processPayroll() that returns an array of doubles. It will take the hours worked array as a parameter and process it. This method must do the following:
Receive the array from main() as a parameter.
Create a new array of doubles to hold the wages information for each employee. This second wages array will have to be the same size as the hours worked array.
Process the data elements by calculating the wages owed to the employee for the number of hours worked and loading this data into the corresponding element of the wages array. The calculation of wages will be done at a fixed pay rate of $38.57/hour with time and a half for over time where over time is any number of hours worked in excess of 40 hours.
Return the wages array.
When processPayroll() returns to main() the code in main() will do two things:
Print out the list of employees identifying them by the array index as described below, how many hours were worked, and and how much is owed to each one.
Print out the sum total of money owed by the company for the payroll.
To make it simple to associate employees to array elements we will assume that the company identifies employees by a payroll number. This number conveniently begins with 100 for the first employee and counts up from there. So you can just add 100 to the array index for the particular employee to display the employee number. You must show the employee number during the input process by prompting for the hours worked by that employee number. You must also print the employee number when displaying the output list of amounts owed to each employee. This means that data for employee #100 is in array location 0, #101 in array location 1, etc.
The input/output format must duplicate the format shown in the sample run below. The user inputs are shown in blue text. You must use printf() to make the amounts in dollars print with two decimal places of accuracy.
Enter number of employees: 4
Enter below the hours worked for the employee number:
Emp Number Hours Wages($)
---------- ----- ---------
100 40 1542.80
101 43 1716.37
102 37 1427.09
103 40 1542.80
Total wages: $6229.06
A template program is attached to help you get started and to get things structured the way they need to be.© BrainMass Inc. brainmass.com December 20, 2018, 3:39 am ad1c9bdddf
The focus of this solution is the processing of arrays. The first method, getPayrollData(), shows how to declare an array and read data into it.
public static int getPayrollData()
// Declare getPayrollData() local variables
Scanner in = new Scanner(System.in);
// Prompt the user for the number of employees to be ...
This solution provides a complete Java program to do basic payroll calculation. It also includes a detailed explanation of how the program works.