Java薪资计划错误

时间:2017-06-28 14:18:28

标签: java error-handling setter getter

我一直收到错误消息“类Payroll中的方法getCalcWage无法应用于给定类型;必需:无参数;找到:int;原因:实际和形式参数列表的长度不同”

经过一些研究后,我试图解决我的代码问题,但没有成功。我必须为我正在参加薪资计划的课程编程。我有两个班,一个是吸气者和二传手,另一个是主要的。任何帮助都会很棒!

public class Payroll {

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

    public void getCalcWages()
    {
        wages = new double [NUM_EMPLOYEES];
        for (int index = 0; index < 7; index++)
        {
            wages[index] = hours[index] * payRate[index];
        } 
    }


    public int getEmployeeId(int index)
    {
        return employeeId[index];
    }

    public int [] getHours()
    {
        return hours;
    }

    public int getHours(int index)
    {
        return hours[index];
    }

    public double [] getPayRate()
    {
        return payRate;
    }

    public double getPayRate (int index)
    {
        return payRate[index];
    }

    public double getWage (int id)
    {
        for (int index = 0; index < 7; index++)
        {
            if (id == employeeId[index])
            {
                return wages[id];
            }
        }
        return -1;
    }

    public double [] getWages()
    {
        return wages;
    }

    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, int wages)
    {
        this.wages[index] = wages;
    }

}


import java.util.Scanner;
import java.text.DecimalFormat;

public class PayrollDemo
{
    public static void main(String[] args){

        int hours;  //hours worked
        double payRate;  //hourly pay rate

        //Create a Scanner object for keyboard input
        Scanner keyboard = new Scanner(System.in);

        //Create a Payroll object
        Payroll testPayroll = new Payroll();


        //Get hours and pay rate for each employee.
        for (int i = 0; i < testPayroll.NUM_EMPLOYEES; i++)
        {
            //Get hours worked 
            System.out.print("Enter the hours worked by employee number " 
            + testPayroll.getEmployeeId(i) + ": "); 
                hours = keyboard.nextInt();


            //Validate hours worked.
            while (hours < 0)
            {
                System.out.println("ERROR: Enter 0 or greater for hours: ");
                hours = keyboard.nextInt();
            }
            //Get the hourly pay rate.
            System.out.print("Enter the hourly pay rate for employee number "
           + testPayroll.getEmployeeId(i) + ": ");

            payRate = keyboard.nextDouble();

            //Store the data in the payroll object.
            testPayroll.setHours(i, hours);
            testPayroll.setPayRate(i, payRate);
        }
        //Create a DecimalFormat object to format output.
        DecimalFormat dollar = new DecimalFormat("#,##0.00");

        //Display the payroll data for each employee.
        System.out.println("\nPAYROLL DATA");
        System.out.println("==============");
        for (int i = 0; i < testPayroll.NUM_EMPLOYEES; i++)
        {
            System.out.println("Employee ID: " + testPayroll.getEmployeeId(i));
            System.out.println("Gross pay: $ " +
                   dollar.format(testPayroll.getCalcWages(i)) + "\n");
        }
    }

0 个答案:

没有答案