title: Calculating with Java Arrays
body: <p>first time poster here.  I am at the end of my rope, ready to give up my pursuit of a career in programming.  I failed to turn in my last assignment because I couldn't get my program to work.  Now, I'm doing some extra practice on my own.  A simple practice assignment using arrays and I can't figure out the last bit of it.  Can someone please tell me what I'm doing wrong here?  When I run it, I can enter the data, but the program quits prior to displaying the output with this error:  </p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
       at Payroll.getGrossPay(Payroll.java:47)
       at PayrollCalc.main(PayrollCalc.java:32)
  </code></pre>
  
  <p>I can display hours and payRate separately, but I cannot display grossPay.  I'm also not happy with my constructor, but not quite sure what to do with it.  The problem required me to initialize the array in the Payroll class.</p>
  
  <hr>
  
  <pre><code>public class Payroll {
      private final int NUM_EMPLOYEES = 3;
      private int[] employeeId = {5658845, 4520125, 7895122}, empId, hours;
      private double[] payRate, wages, grossPay;
  
      public Payroll()
  {
      empId = employeeId;
  }
  public void setEmployeeId(int[] employeeId)
  {
      empId = employeeId;
  }
  public void setEmpHours(int[] empHoursIn)
  {
      hours = empHoursIn;
  }
  public void setEmpPayRate(double[] empPayRateIn)
  {
      payRate = empPayRateIn;
  }
  public int[] getEmployeeId()
  {
      return empId;
  }
  public int[] getEmpHours()
  {
      return hours;
  }
  public double[] getEmpPayRate()
  {
      return payRate;
  }
  public double[] getGrossPay()
  {
      for (int count = 0; count &lt; NUM_EMPLOYEES; count++)
      {
          grossPay[count] = getEmpPayRate()[count] * getEmpHours()[count];
      }
  
      return grossPay;
  }
  }
  </code></pre>
  
  <hr>
  
  <p>import java.util.Scanner;</p>
  
  <pre><code>public class PayrollCalc 
  {
  public static void main(String[] args) 
  {
      int count;
      final int NUM_EMPLOYEES = 3;
      int[] empHours = new int[NUM_EMPLOYEES];
      double[] empPayRate = new double[NUM_EMPLOYEES];
      Scanner keyboard = new Scanner(System.in);
      Payroll payroll = new Payroll();
  
      for (count = 0; count &lt; NUM_EMPLOYEES; count++)
      {
          System.out.print("Enter total hours for employee " +  
                             payroll.getEmployeeId()[count] + ": ");
          empHours[count] = keyboard.nextInt();
          payroll.setEmpHours(empHours);
  
          System.out.print("Enter pay rate for employee " + 
                             payroll.getEmployeeId()[count] + ": ");
          empPayRate[count] = keyboard.nextDouble();
          payroll.setEmpPayRate(empPayRate);
      }
  
      System.out.println("\nEMPLOYEE ID\tGROSS PAY");
      System.out.println("-----------     ---------");
  
      for (count = 0; count &lt; NUM_EMPLOYEES; count++)
      {
          System.out.println(payroll.getEmployeeId()[count] + "\t\t" + 
                             payroll.getGrossPay()[count]);           
      }
    }
    }
  </code></pre>
  
  <hr>
  
  <p>Thanks in advance for your help!</p>
  
  <p>Stef</p>