I have a program that uses 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 employee's hourly pay rate
wages.- An array of seven doubles to hold each employee's gross wages
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.
I've had a number of errors when I compile it:
Payroll1.java:34: cannot find symbol
symbol : variable ID
location: class Payroll1
EmployeeID = ID;
^
Payroll1.java:35: cannot find symbol
symbol : variable pr
location: class Payroll1
payRate = pr;
^
Payroll1.java:36: cannot find symbol
symbol : variable hr
location: class Payroll1
hours = hr;
^
Payroll1.java:40: cannot find symbol
symbol : variable ID
location: class Payroll1
return EmployeeID[i]=ID;
^
Payroll1.java:54: cannot find symbol
symbol : variable pr
location: class Payroll1
return payRate[i]= pr;
^
Payroll1.java:59: operator >= cannot be applied to double[],int
if(hours>=0)
^
Payroll1.java:64: possible loss of precision
found : double
required: int
return hours[i]= hr;
^
Payroll1.java:69: i is already defined in getGrossPay(int,int)
for( int i=0; i<NUM_EMPLOYEES; i++)
^
Payroll1.java:71: incomparable types: int[] and int
if(EmployeeID == i)
^
Payroll1.java:74: incompatible types
found : double[]
required: double
return GrossPay;
The code is as follows:
public class Payroll1
{
public final int NUM_EMPLOYEES = 7; // constants of employees
private int[] EmployeeID = {5658845, 4520125, 7895122, 8777541, 8451277,
1302850, 7580489};
private double[] hours = new double[NUM_EMPLOYEES];
private double[] payRate = new double[NUM_EMPLOYEES];
private double[] GrossPay = new double[NUM_EMPLOYEES];
public double getGrossPay(int i)
{
return payRate[i] * hours[i];
}
/** Constructor
@param employeeID.
@param hours.
@param payRate.
*/
public Payroll1(int[] EmployeeID, double[] hours, double[] payRate)
{
EmployeeID = ID;
payRate = pr;
hours = hr;
}
public int getEmployeeID(int i)
{
return EmployeeID[i]=ID;
}
public void setEmployeeID(int i, int ID)
{
EmployeeID[i]=ID;
}
public void setPayRate(int i, double pr)
{
if(pr>=6.00)
payRate[i]= pr;
}
public double getPayRate(int i)
{
return payRate[i]= pr;
}
public void setHours(int i, int hr)
{
if(hours>=0)
hours[i]= hr;
}
public int getHours(int i, int hr)
{
return hours[i]= hr;
}
public double getGrossPay(int ID, int i)
{
for( int i=0; i<NUM_EMPLOYEES; i++)
{
if(EmployeeID == i)
{
GrossPay[i] = hours[i]* payRate[i];
return GrossPay;
}
}
return 0.0;
}
}