Hey all, I need some help on this program cause I'm stumped. Everytime I compile this program is gives me an error of either "cannot find symbol" or "int cannot be dereferenced". I'm still playing around with the code but I might have to put the other class in a separate program because I don't know what to do. Thanks in advance for your help I really appreciate it.

import java.util.Scanner;


class PayrollGet
  
{
  public static void main(String[] args) {
  
    
    Scanner kb = new Scanner(System.in);

    int payroll;
    int hours;
    double payRate;
    double wages;
    int employeeID;
    
    
    for (int i = 0; i < 7; i++) 
    
    {
      System.out.println("Employee #" + (i + 1));


      do
      {
        
        System.out.print("\tHours: ");
        hours = Integer.parseInt(kb.nextLine());

        if(hours<0)
          System.out.println("must be >=0");


      } 
      while (hours < 0);
      payroll.setHours(i, hours);


      do 
      {
        
        System.out.print("\tPay Rate: ");
        payRate = Double.parseDouble(kb.nextLine());


      } 
      while (payRate < 6.00);
      payroll.setPayRate(i, payRate);


      employeeID = payroll.getEmployeeID(i);
      wages = payroll.calculateGrossPay(employeeID);
      payroll.setWages(i, wages);

      }
      for (int i = 0; i < 7; i++) 
      {
        
        System.out.print("Employee ID: " + payroll.getEmployeeID(i));
        System.out.println("\tGross Wages: " + payroll.getWages(i));
        
    }
  }
}


    public class Payroll {


      private int[] employeeID = { 5658845, 4520125, 7895122, 877541, 8451277,
1302850, 7580489 };

      private int[] hours = new int[7];


      private double[] payRate = new double[7];


      private double[] wages = new double[7];



      public int getEmployeeID(int index) 

      {
        return employeeID[index];
      }

      public int getHours(int index) 

      {
        return hours[index];
      }

      public double getPayRate(int index) 

      {
        return payRate[index];
      }

      public double getWages(int index) 

      {
        return wages[index];
      }

      public void setEmployeeID(int index, int employeeID) 

      {
        this.employeeID[index] = employeeID;
      }

      public void setHours(int index, int hours) 

      {
        this.hours[index] = hours;
      }

      public void setPayRate(int index, double payRate) 

      {
        this.payRate[index] = payRate;
      }

      public void setWages(int index, double wages) 

      {
        this.wages[index] = wages;
      }

      public double calculateGrossPay(int theEmployeeID) 

      {
        double grossPay = 0;


        int employeeIndex = -1;
        for (int i = 0; i < employeeID.length; i++) 

        {
          if (employeeID[i] == theEmployeeID) 

          {
            employeeIndex = i;
            break;
          }
        }


        if (employeeIndex != -1) 

        {

          int h = hours[employeeIndex];
          double r = payRate[employeeIndex];


          grossPay = (h * r);
        }

        return grossPay;
      }
}

You have an int called payroll (declared on line 12) that you try to invoke methods on.

You have an int called payroll (declared on line 12) that you try to invoke methods on.

Would you suggest I rename it? I had some variables in there already though...

Would you suggest I rename it? I had some variables in there already though...

it looks like you just mispelled the Payroll class.

Payroll.setHours(i,hours);//..change everywhere you have payroll.method()

I'm also not sure if you have these classes in the same file or separate files, so you will need to create a new Payroll object depending.

it looks like you just mispelled the Payroll class.

Payroll.setHours(i,hours);//..change everywhere you have payroll.method()

I'm also not sure if you have these classes in the same file or separate files, so you will need to create a new Payroll object depending.

Okay I fixed that and took away the int declaration of Payroll, and separated the classes into their own files. I'm getting an error on lines 36 as well as some on 48-58 that it can't find the symbol for the methods I use (setHours,getpayRate,getEmployeeID) however I don't know what else I should use in order to get those...

import java.util.Scanner;

public class Payroll
  
{
  public static void main(String[] args) {
  
    
    Scanner kb = new Scanner(System.in);


    int hours;
    double payRate;
    double wages;
    int employeeID;
    
    
    for (int i = 0; i < 7; i++) 
    
    {
      System.out.println("Employee #" + (i + 1));


      do
      {
        
        System.out.print("\tHours: ");
        hours = Integer.parseInt(kb.nextLine());

        if(hours<0)
          System.out.println("must be >=0");


      } 
      while (hours < 0);
      Payroll.setHours(i, hours);


      do 
      {
        
        System.out.print("\tPay Rate: ");
        payRate = Double.parseDouble(kb.nextLine());


      } 
      while (payRate < 6.00);
      Payroll.setPayRate(i, payRate);


      employeeID = Payroll.getEmployeeID(i);
      wages = Payroll.calculateGrossPay(employeeID);
      Payroll.setWages(i, wages);

      }
      for (int i = 0; i < 7; i++) 
      {
        
        System.out.print("Employee ID: " + Payroll.getEmployeeID(i));
        System.out.println("\tGross Wages: " + Payroll.getWages(i));
        
    }
  }
}

You have completely changed your program. In your first post the main class was PayrollGet, now it's in the Payroll class.

You have the exact same problem only now you have reversed it.
Payroll.setWages(i,wages) ...calls to methods like that will not work. Payroll is the name of the class you are currently in, and the Payroll class contains no such methods.

If you want to access methods from a separate class, you need to create an instance of that class to access those methods.
So if your methods are now in the PayrollGet class, you need to create an instance of that class in your Payroll class.

e.g. PayrollGet payRoll = new PayrollGet();

Once you do this in your Payroll class, you can access all methods and static variables from the PayrollGet class by simply typing:
payRoll.theMethodName();


If you are totally confused, post both classes back here and I will help you clean it up.

commented: Helpful advice, concisely written to boot. +0

You have completely changed your program. In your first post the main class was PayrollGet, now it's in the Payroll class.

You have the exact same problem only now you have reversed it.
Payroll.setWages(i,wages) ...calls to methods like that will not work. Payroll is the name of the class you are currently in, and the Payroll class contains no such methods.

If you want to access methods from a separate class, you need to create an instance of that class to access those methods.
So if your methods are now in the PayrollGet class, you need to create an instance of that class in your Payroll class.

e.g. PayrollGet payRoll = new PayrollGet();

Once you do this in your Payroll class, you can access all methods and static variables from the PayrollGet class by simply typing:
payRoll.theMethodName();


If you are totally confused, post both classes back here and I will help you clean it up.

You're a genius lol. But seriously thanks for the help it worked out fine.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.