Question: Preliminaries Create a project submission folder, in the form Lab#FirstNameLastName. For example, mine would be Lab7DavidLiu Create an Eclipse Java Project. Add a Java class

Preliminaries

Create a project submission folder, in the form Lab#FirstNameLastName. For example, mine would be Lab7DavidLiu

Create an Eclipse Java Project.

Add a Java class named Payroll to your project

Add a Java class named ArrayOps to your project

Add a Java class called Main to your project

Exercises

Part 1) The ArrayOps class 5 points

ArrayOps is the first class we will make, as you make use of it in the others.

Note: In the event I dont get to it in lecture before this is assigned, you can use arrays as return types an arguments. A method:

public char[] findLetter(int[] blah){//stuff}

Would take an int array as an argument and return a char array.

ArrayOps has no constructor or fields, so rejoice! Instead, it has the following methods:

a public static method called copyIntArray. It takes an int array as an argument and returns a brand new one, made by copying the values from the first array

a public static method called copyDoubleArray. It does the same as copyIntArray, but takes and returns a double array

two public static methods both named sumArray. One should take an int array, the other should take a double array. The one that takes an int array should return an integer and the one that takes a double should return a double.

Both copyIntArray and copyDoubleArray should follow this same general algorithm. While I write it using int, replace it with double for the DoubleArray method:

Make a new int array -> the size of the array should match the size of the argument array

Loop through the values in the array passed as an argument

For each value, copy it into the new array

Return the new array

For the summing methods, you should sum the values of the array passed as an argument and pass the sum. This should be similar to other for loop summations weve done in the past.

Part 2) The Payroll Class 10 points

The second part is focused around making the Payroll Class itself.

Payroll should have a private final constant int field called SIZE (or something like it). Set it to 7.

The Payroll class needs the four following fields:

employeeID an array of Strings, which will hold employee ID numbers. It should be private and have size SIZE

hours an array of integers, which will hold the hours the employees worked. It should have size SIZE

payRates an array of doubles holding the pay rates for employees

wages an array of doubles holding the wages for employees

The Payroll constructor takes no arguments. It should initialize wages to an empty array of size SIZE. It should assign the 7 values to the employeeID array. You may use whatever IDs you wish. An example of 7 values is:

7623A, 1182B, 1182C, 1337G, 8910Y, 2323X, 6921F

Payroll should have getters for all fields

Payroll should have setters for hours and payRates.

Instead of just using field = argument, hours should use ArrayOps copyIntArray method (hours = copyIntArray(argumentarray)

payRates should use the copyDoubleArray

Payroll needs a method setWages. setWages is void and has the following algorithm:Using a regular for loop:

Calculate pay = hours * payRate for a given index

Set wage[i] = pay, where i is the current elements of the array being accessed

Payroll should have a toString method, that prints out:

PAYROLL DATA

-----

For each Employee:

EmployeeID : the ID (from the array)

Pay: the wage (from the array) . Use a DecimalFormat object to round to two decimal points

The sum of hours and wages, using ArrayOps sum methods

Sample output:

PAYROLL DATA

-----

Employee ID: 5658845

Gross pay: $626.00

Employee ID: 4520125

Gross pay: $666.00

Employee ID: 7895122

Gross pay: $720.00

Employee ID: 8777541

Gross pay: $897.75

Employee ID: 8451277

Gross pay: $300.00

Employee ID: 1302850

Gross pay: $300.00

Employee ID: 7580489

Gross pay: $400.00

Sum Hours: 272

Sum Pay: $3909.75

Part 3) The Main Class 5 points

The Main Class is responsible for using Payroll.

Main should make three arrays an array of ints and one double array. They should be all be size 7.

Main should make an instance of Payroll.

Main should then loop through the employeeID array of the Payroll object. You can store it temporarily (String[] arr = employeeIDs accessor method] or just call the method directly in the for loop if you are using the enhanced for loop. The loop should:

Ask the user for the hours worked by the current employee and store it in the int array

Ask the user for the pay rate for the current employee and store it in one of the double arrays

It should look something like this:

Enter the hours worked by employee number 5658845: 40

Enter the hourly pay rate for employee number 5658845: 15.65

Enter the hours worked by employee number 4520125: 37

Enter the hourly pay rate for employee number 4520125: 18.00

Enter the hours worked by employee number 7895122: 40

Enter the hourly pay rate for employee number 7895122: 18.00

Enter the hours worked by employee number 8777541: 35

Enter the hourly pay rate for employee number 8777541: 25.65

Enter the hours worked by employee number 8451277: 40

Enter the hourly pay rate for employee number 8451277: 7.50

Enter the hours worked by employee number 1302850: 40

Enter the hourly pay rate for employee number 1302850: 7.50

Enter the hours worked by employee number 7580489: 40

Enter the hourly pay rate for employee number 7580489: 10.00

Once the for loop is done, use Payrolls setter methods to set the int array as the hours and the double array as the rates.

Call Payroll.setWages()

Finally, print out Payroll. It should use the toString written for it above.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!