473,473 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Trouble with payroll program in Java

1 New Member
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:

Expand|Select|Wrap|Line Numbers
  1.  import java.util.Scanner;
  2.  
  3.  
  4. class Payroll
  5. {
  6.     private String [] employeeId;
  7.     private double [] hours;
  8.      private double [] payRate;
  9.  
  10.      public Payroll()
  11.      {
  12.         employeeId = new String [] { "5658845", "4520125", "7895122" , "8777541", "8451277", "1302850", "7580489" };
  13.         hours = new double[7];
  14.           payRate = new double[7];
  15.      }
  16.  
  17.      public String [] getEmployeeId () 
  18.      {
  19.      return employeeId;
  20.      }
  21.  
  22.      public void setHours (double [] hrs)
  23.      {
  24.       hours = hrs;
  25.      }
  26.  
  27.       public void setPayRate (double [] rate)
  28.       {
  29.       payRate = rate;
  30.       }
  31.  
  32.      public int getGrossPay (int employeeId)
  33.      {
  34.        int index = 0;
  35.         for(int i = 0; i < employeeId; i++)
  36.          {
  37.           if (employeeId [i].equalsIgnoreCase (employeeId) )
  38.           {
  39.              index = i;
  40.               break;
  41.           }
  42.  
  43.  
  44.          }
  45.  
  46.          return hours [index] * payRate [index]; 
  47.  
  48.  
  49.  
  50.         }
  51.  
  52.  
  53. }
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. public class PayrollDriver
  63. {
  64.    public static void main (String args[])
  65.     {
  66.      Scanner in = new Scanner (System.in);
  67.  
  68.      Payroll pay = new Payroll();
  69.  
  70.      String [] EmployeeId = Payroll.getEmployeeId();
  71.  
  72.      double [] localHours = new double [EmployeeId.length];
  73.  
  74.      for(double i = 0; i < EmployeeId.length; i++)
  75.       {
  76.         System.out.println ("Please enter the hours worked on " + EmployeeId[i]);
  77.          localHours[i] = in.nextDouble();
  78.       }
  79.  
  80.       pay.setHours(localHours);
  81.  
  82.  
  83.  
  84.          double [] localPayRate = new double [EmployeeId.length];
  85.  
  86.      for(double i = 0; i < EmployeeId.length; i++)
  87.       {
  88.         System.out.println ("Please enter the pay rate for Employee " + EmployeeId[i]);
  89.          localPayRate[i] = in.nextDouble();
  90.       }
  91.  
  92.       pay.setPayRate(localPayRate);
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.       for (int i = 0; i < employeeId.length; i++)
  100.       {
  101.          System.out.print("The gross pay for Employee " + EmployeeId[i]); //"The gross pay for employee Id
  102.         System.out.println( " is " + pay.getHours(EmployeeId[i])* pay.getPayRate(EmployeeId[i]) ); //Display gross pay          
  103.       }
  104.  
  105.     }
  106.  
  107. }
  108.  
Those are the errors I get:

Expand|Select|Wrap|Line Numbers
  1.  PayrollDriver.java:47: array required, but int found
  2.           if (employeeId [i].equalsIgnoreCase (employeeId) )
  3.                          ^
  4. PayrollDriver.java:56: possible loss of precision
  5. found   : double
  6. required: int
  7.          return hours [index] * payRate [index]; //hours [i] * payrate [i];
  8.                               ^
  9. PayrollDriver.java:80: non-static method getEmployeeId() cannot be referenced from a static context
  10.      String [] EmployeeId = Payroll.getEmployeeId();
  11.                                    ^
  12. PayrollDriver.java:86: possible loss of precision
  13. found   : double
  14. required: int
  15.         System.out.println ("Please enter the hours worked on " + EmployeeId[i]);
  16.                                                                              ^
  17. PayrollDriver.java:87: possible loss of precision
  18. found   : double
  19. required: int
  20.          localHours[i] = in.nextDouble();
  21.                     ^
  22. PayrollDriver.java:98: possible loss of precision
  23. found   : double
  24. required: int
  25.         System.out.println ("Please enter the pay rate for Employee " + EmployeeId[i]);
  26.                                                                                    ^
  27. PayrollDriver.java:99: possible loss of precision
  28. found   : double
  29. required: int
  30.          localPayRate[i] = in.nextDouble();
  31.                       ^
  32. PayrollDriver.java:109: cannot find symbol
  33. symbol  : variable employeeId
  34. location: class PayrollDriver
  35.       for (int i = 0; i < employeeId.length; i++)
  36.                           ^
  37. PayrollDriver.java:112: cannot find symbol
  38. symbol  : method getHours(java.lang.String)
  39. location: class Payroll
  40.         System.out.println( " is " + pay.getHours(EmployeeId[i])* pay.getPayRate(EmployeeId[i]) ); //Display gross pay          
  41.                                         ^
  42. PayrollDriver.java:112: cannot find symbol
  43. symbol  : method getPayRate(java.lang.String)
  44. location: class Payroll
  45.         System.out.println( " is " + pay.getHours(EmployeeId[i])* pay.getPayRate(EmployeeId[i]) ); //Display gross pay          
  46.                                                                      ^
  47. 10 errors
  48.  
  49.  
Any help would be gladly appreciated, I know there is something important I am missing somewhere. Thanks in advance!
Nov 22 '11 #1
0 1774

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Randi | last post by:
Hi, Looking for some help with this payrool project I have for class. This is what the instructor asks for so far. I have it working without errors but am getting some funky numbers. I am not...
10
by: ycg0771 | last post by:
I'm trying to modify the following program so that it uses a class to store and retrieve the employee's name, the hourly rate, and the number of hours worked. Use a constructor to initialize the...
5
by: jbailey006 | last post by:
I am trying to add the following information to a payroll program I am working on for assignment. Modify the Payroll Program so that it uses a class to store and retrieve the employee's name, the...
1
by: Akinyemi | last post by:
I have almost finished writing my Payroll Program. But I am wondering how the program can be used for different months. For example, after, say January 2007 Payroll, the user would want to prepare...
1
by: Richards | last post by:
Pls help me with code for a payroll in c++. how to declare my variable and use functions to segment the program. thanks Richards
8
by: teddarr | last post by:
I have a program that uses Employee as the superclass. It has subclasses of SalariedEmployee, CommissionEmployee, BasePlusCommissionEmployee, and HoulyEmployee. This program works great to provide...
6
by: aureao4 | last post by:
I'm new to Java and programming. I'm trying to code a payroll program and continue getting errors. The program worked last week, this week I have to add set, get and a class. I've written the class...
3
by: suryawati | last post by:
Dear All, I am running a java serial program ( Black Box on commapi package ) on a Linux. But when Main Menu can displayed, automatically program stop for running and I can't do anything with...
2
by: alexlunar | last post by:
Hello, I am trying to figure out when I have done wrong or what i have not included in my most recent edit of my payroll code. My code from last week was // Week 2 payroll // payroll program...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.