Hello,

I am a novice programmer and I was given the following task: write a Payroll class that uses the following arrays as fields : employeeId (holds 7 integers that are initialized, I placed them in my code below), hours and payRate (both are doubles and hold 7 numbers). I need a default constructor, getEmployeeId accessor, setHours and setPayRate mutators, and getGrossPay, which accepts employeeId as an argument and returns gross pay for the employee given.
The program then should display the number of each employee and ask for the employee's hours and pay rate, and then display the employee's number and gross pay. This is the code I have so far:

import java.util.Scanner;


class Payroll
{
    private String [] employeeId;
    private double [] hours;
	 private double [] payRate;
    
     public Payroll()
     {
        employeeId = new String [] { "5658845", "4520125", "7895122" , "8777541", "8451277", "1302850", "7580489" };
        hours = new double[7];
		  payRate = new double[7];
     }
    
     public String [] getEmployeeId () 
     {
     return employeeId;
     }
    
     public void setHours (double [] hrs)
     {
      hours = hrs;
     }
	  
	  public void setPayRate (double [] rate)
	  {
	  payRate = rate;
	  }
    
     public int getGrossPay (int employeeId)
     {
       int index = 0;
        for(int i = 0; i < employeeId; i++)
         {
          if (employeeId [i].equalsIgnoreCase (employeeId) )
          {
             index = i;
              break;
          }
          
           
         }
        
         return hours [index] * payRate [index]; 

          
          
        }


}
    
    

    
    
    


public class PayrollDriver
{
   public static void main (String args[])
    {
     Scanner in = new Scanner (System.in);
    
     Payroll pay = new Payroll();
    
     String [] EmployeeId = Payroll.getEmployeeId();
    
     double [] localHours = new double [EmployeeId.length];
    
     for(double i = 0; i < EmployeeId.length; i++)
      {
        System.out.println ("Please enter the hours worked on " + EmployeeId[i]);
         localHours[i] = in.nextDouble();
      }
      
      pay.setHours(localHours);
		
		
		
		 double [] localPayRate = new double [EmployeeId.length];
    
     for(double i = 0; i < EmployeeId.length; i++)
      {
        System.out.println ("Please enter the pay rate for Employee " + EmployeeId[i]);
         localPayRate[i] = in.nextDouble();
      }
      
      pay.setPayRate(localPayRate);

		
		
		
		
      
      for (int i = 0; i < employeeId.length; i++)
      {
         System.out.print("The gross pay for Employee " + EmployeeId[i]); //"The gross pay for employee Id
        System.out.println( " is " + pay.getHours(EmployeeId[i])* pay.getPayRate(EmployeeId[i]) ); //Display gross pay          
      }
    
    }
    
}

Those are the errors I get:

PayrollDriver.java:47: array required, but int found
          if (employeeId [i].equalsIgnoreCase (employeeId) )
                         ^
PayrollDriver.java:56: possible loss of precision
found   : double
required: int
         return hours [index] * payRate [index]; //hours [i] * payrate [i];
                              ^
PayrollDriver.java:80: non-static method getEmployeeId() cannot be referenced from a static context
     String [] EmployeeId = Payroll.getEmployeeId();
                                   ^
PayrollDriver.java:86: possible loss of precision
found   : double
required: int
        System.out.println ("Please enter the hours worked on " + EmployeeId[i]);
                                                                             ^
PayrollDriver.java:87: possible loss of precision
found   : double
required: int
         localHours[i] = in.nextDouble();
                    ^
PayrollDriver.java:98: possible loss of precision
found   : double
required: int
        System.out.println ("Please enter the pay rate for Employee " + EmployeeId[i]);
                                                                                   ^
PayrollDriver.java:99: possible loss of precision
found   : double
required: int
         localPayRate[i] = in.nextDouble();
                      ^
PayrollDriver.java:109: cannot find symbol
symbol  : variable employeeId
location: class PayrollDriver
      for (int i = 0; i < employeeId.length; i++)
                          ^
PayrollDriver.java:112: cannot find symbol
symbol  : method getHours(java.lang.String)
location: class Payroll
        System.out.println( " is " + pay.getHours(EmployeeId[i])* pay.getPayRate(EmployeeId[i]) ); //Display gross pay          
                                        ^
PayrollDriver.java:112: cannot find symbol
symbol  : method getPayRate(java.lang.String)
location: class Payroll
        System.out.println( " is " + pay.getHours(EmployeeId[i])* pay.getPayRate(EmployeeId[i]) ); //Display gross pay          
                                                                     ^
10 errors

Any help would be gladly appreciated, I know there is something important I am missing somewhere. Thanks in advance!

Thank you for the reply, does this sound better :

public int getGrossPay (String myEmployeeId)
     {
       int index = 0;
        for(int i = 0; i < myEmployeeId; i++)
         {
          if (myEmployeeId [i].equalsIgnoreCase (employeeId) )
          {
             index = i;
              break;
          }

Also any idea why I am getting all the found double, required int errors? I would really appreciate any insight on this. :)

Yes... You have 2 for loops like this...
for(double i = 0; i < EmployeeId.length; i++)
Replace with...
for(int i = 0; i < EmployeeId.length; i++)

This article has been dead for over six months. Start a new discussion instead.