Need Help With Program

Payroll Class Array

Page 1 of 1

1 Replies - 937 Views - Last Post: 08 April 2010 - 10:02 PM Rate Topic: -----

#1 Dana Pozer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 08-April 10

Need Help With Program

Posted 08 April 2010 - 09:54 PM

I need help with this program :P

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 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.

This is what I've gotten so far :)

import java.util.Scanner;

	 public class PayrollTracker
	 {
	 private final int NUM_EMPLOYEES = 7;
    private int[] employeeId = {5658845, 4520125, 7895122, 8777541, 8451277, 1302850, 7580489};
    private int[] hours = new int[NUM_EMPLOYEES];
    private double[] payRate = new double[NUM_EMPLOYEES];
    private double[] wages = new double[NUM_EMPLOYEES];

    public int getEmployeeId(int id)
    {
        return employeeId[id];
    }
    public double getWages(int id)
    {
        return wages[id];
    }
    public void setPayRate(int id, double pr)
    {
        payRate[id]=pr;
    }
    public void setHours(int id, int h)
    {
        hours[id]=h;
    }
    public void calcGrossWages()
    {
        for(int i = 0; i < NUM_EMPLOYEES; i++) 
        {
            GrossWages[i] = hours[i]*payRate[i];
        }
    }            

	 public static void main(String[] args)
    {    
       int hrs;
		 double payr;
		 
        PayrollTracker pr = new PayrollTracker();
		  Scanner keyboard = new Scanner(System.in);
		  for(int i = 0; i < 7; i++)
		  {
		  System.out.println(pr.getEmployeeId(i));            
        System.out.println("Enter the amount of hours the employee worked ");
       hrs = keyboard.nextInt();
		  pr.setHours(i, hrs);
		  System.out.println("Enter the pay rate at which the employee was paid ");
		  payr = keyboard.nextDouble();
		  pr.setPayRate(i, payr);
		  }
		  pr.calcGrossWage();
		  for(int i = 0; i < 7; i++)
		  {
		 		  System.out.println(pr.getEmployeeId(i) + " - " + pr.getWages(i));
		  }
		  }}


I'm getting a few error messages. Help anyone?

Moderator Edit: In the future, please remember --> :code:.

-Locke

Is This A Good Question/Topic? 0
  • +

Replies To: Need Help With Program

#2 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: Need Help With Program

Posted 08 April 2010 - 10:02 PM

Please use the code tags :code:

pr.calcGrossWage();
YOu have a calcGrossWages (notice the s) method, but not a calcGrossWage

public void calcGrossWages()
{
for(int i = 0; i < NUM_EMPLOYEES; i++)
{
GrossWages[i] = hours[i]*payRate[i];
}
} 

You never declare GrossWages. You do declare wages however
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1