Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA 2. Payroll Class Write a Payroll class that uses the following arrays as fields: employeeId. An array of seven integers to hold employee identification

JAVA

2. Payroll Class Write a Payroll class that uses the following arrays as fields: employeeId. An array of seven integers to hold employee identification numbers. The array should be initialized with the following numbers: 5658845 4520125 7895122 8777541 8451277 1302850 7580489 hours. An array of seven integers to hold the number of hours worked by each employee payRate. An array of seven doubles to hold each employees hourly pay rate wages. An array of seven doubles to hold each employees gross wages The 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 employeeId array. That same employees pay rate should be stored in element 0 of the payRate array. In addition to the appropriate accessor and mutator methods, the class should have a method that accepts an employees identification number as an argument and returns the gross pay for that employee.

Demonstrate the class in a complete program that displays each employee number and asks the user to enter that employees hours and pay rate. It should then display each employees identification number and gross wages. Input Validation: Do not accept negative values for hours or numbers less than 6.00 for pay rate.

Need help!! So far, I have done the code but getting error

public class Payroll { private int [] employeeID = { 5658845, 4520125, 7895122, 8777541, 8451277, 1302850, 7580489 }; private final int NUM_OF_EMPLOYEES = 7; private int [] hours = new int [7]; private double [] payRate = new double [7]; private double [] wages = new double [7]; private double []grossPay = new double[7]; public Payroll() { // initialize all other arrays with 0 values

for( int index = 0; index < employeeID.length; index++ ) { hours[ index ] = 0; payRate[ index ] = 0.0; wages[ index ] = 0.0; } // end for } public double getEmployeeID(int index){ return employeeID[index]; } public double getHours(int index){ return hours[index]; } public double getPayrate(int index){ return payRate[index]; } public double getWages(int index){ return wages[index]; } public void setEmployeeID(int employeeID, int index){ this.employeeID[index] = employeeID; }

public void setHours(int hours, int index ) { this. hours[index] = hours; }

public void setPayrate(double payRate, int index){ this. payRate[index] = payRate; } public void setWages(double wages, int index){ this.wages[index] = wages; } public double calculateGrosspay(int employeeId){ double grossPay = 0; int employeeIndex = - 1; //index of the employee for (int i = 0; i < employeeID.length; i++) { if (employeeID[i] == employeeId) { employeeIndex = i; break; } } if (employeeIndex != - 1) { //gross pay for if employee was found. int h = hours[employeeIndex]; double r = payRate[employeeIndex]; grossPay = (h * r); //calculate the gross pay

} return grossPay; } }

import java.util.Scanner;

public class PayrollDemo { public static void main (String[] args){ int hours; double payRate; Scanner keyboard = new Scanner (System.in); Payroll payroll = new Payroll(); for (int index =0; index < 7; index++) { System.out.println("EmployeeID:" + payroll.getEmployeeID(index)); while (hours < 0){ // Validate the input. System.out.println("Please enter a positive number of hours worked:"); hours = keyboard.nextInt(); payroll.setHours(index, hours); } while (payRate < 6.00) { System.out.println("Please enter the employees hourly rate more than $6.00:"); payRate = keyboard.nextDouble(); payroll.setPayrate(index, payRate); } } for (int index =0; index < 7; index++) { System.out.println("Employee ID: " + payroll.getEmployeeID(index)); System.out.println("Grosspay: " + payroll.getWages(index)); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions