繁体   English   中英

类型中的方法不适用于参数

[英]the method in type not applicable for the arguments

我收到此错误消息:

发现2个错误:

错误:PayCalculator 类型中的方法determineTaxRate(double) 不适用于参数()

错误:PayCalculator 类型中的方法 calculateNetPay(double, double) 不适用于参数 ()

你能告诉我该怎么做才能解决这个问题吗?

public class PayCalculator
{
    private double hourlyRate;
    private double hoursWorked;

     /**
     * Two parameter constructor
     * Add hourlyRate and hoursWorked
     * @param the hourly rate
     * @param the hours worked
     */
    public PayCalculator(double aHourlyRate, double aHoursWorked)
    {
        hourlyRate = aHourlyRate;
        hoursWorked = aHoursWorked;
    }

    /**
    * sets the hourly rate
    * @return hourlyRate
    */ 
    public void setHourlyRate(double aHourlyRate)
    {
        hourlyRate = aHourlyRate;
    }

    /**
    * gets the hourly rate
    * @param hourlyRate
    */
    public double getHourlyRate()
    {
        return hourlyRate;
    }

    /**
    * sets the hours worked
    * @return hoursWorked
    */ 
    public void setHoursWorked(double aHoursWorked)
    {
        hoursWorked = aHoursWorked;
    }

    /**
    * gets the hours worked
    * @param hours worked
    */
    public double getHoursWorked()
    {
        return hoursWorked;
    }



    public boolean workedOvertime()
    {
        if (hoursWorked > 40)
        {
            return true;
        }
        else 
        {
            return false;
        }
    }

    public double numHoursOvertime()
    {
        if (hoursWorked > 40)
        {
            return hoursWorked - 40;
        }
        else 
        {
            return 0;
        }
    }

    public double calculateGrossPay()
    {
        if (hourlyRate  <= 10.25)
        {
            if (hourlyRate <= 40)
                return hourlyRate * hoursWorked;
        }
        else 
        {  
            double grossPay = ((40 * hourlyRate) + ((hourlyRate * 2) * hoursWorked - 40));
            return grossPay;
        }

        if (hoursWorked <= 60)
        {
            return hourlyRate * hoursWorked;
        }
        else
        {
            return 60 * hourlyRate;
        }
    }

    public double determineTaxRate(double grossPay)
    {
        if (grossPay >= 800)
        {
            double tax = 0;
            tax = grossPay * 0.37;
            return tax;
        }
        else if ( grossPay >= 400)
        {
            double tax = 0;
            tax = grossPay * 0.22;
            return tax;
        }
        else
        {
            double tax = 0;
            tax = grossPay * 0.12;
            return tax;
        }
    }

    public double calculateNetPay(double grossPay, double tax)
    {
        double calculateNetPay = grossPay - tax;
        return calculateNetPay;
    }

    public void printData()
    {
        System.out.println("Hours Worked: " + hoursWorked);
        System.out.println("Hourly rate: " + hourlyRate);
        System.out.println("Number of hours of overtime worked: " + numHoursOvertime());
        System.out.println("Worked overtime? " + workedOvertime());
        System.out.println("Gross pay: " + calculateGrossPay());
        System.out.println("Tax Rate: " + determineTaxRate());
        System.out.println("Net Pay: " + calculateNetPay());
    }

}

你在打电话

determineTaxRate()

但是您的方法定义为:

public double determineTaxRate(double grossPay)
{

与您的其他错误相同。 您需要将double传递给该方法。 比如这个:

determineTaxRate(calculateGrossPay())

您尚未为从printData()方法调用的方法指定参数,例如:

System.out.println("Net Pay: " + calculateNetPay());

您正在使用 0 个参数调用calculateNetPay() ,在您指定的方法定义中,它需要 2 个双参数。

public double calculateNetPay(double grossPay, double tax) { ... }

这同样适用于您遇到的其他错误。

你的方法用一个参数定义。但你没有传递任何参数。

对于calculateNetPay(),您也在做同样的事情。

你已经像这样声明了你的方法:

public double determineTaxRate(double grossPay)

然后像这样调用它:

determineTaxRate()

显然,您在调用该方法时错过了一个参数

通过确定税收率(someDoubleVar)解决这个问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM