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

标签 java parameters compiler-errors arguments boolean

我收到此错误消息:

找到2个错误:

Error: The method determineTaxRate(double) in the type PayCalculator is not applicable for the arguments ()

Error: The method calculateNetPay(double, double) in the type PayCalculator is not applicable for the arguments ()



您能告诉我该怎么做吗?
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())

关于java - 类型中的方法不适用于参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15285975/

相关文章:

iphone - NSURL 添加参数到 fileURLWithPath 方法

c++ - 使用 C 的 '...' 参数包作为 C++ 模板值?

windows - Visual Studio 编译但 exe 不存在

java - Swing:FileDialog 陷入漫长的过程

java - 从枚举序数转换为枚举类型

java - 发送短信时,应用程序在 getContentResolver().query(...) 上停止

spring - 如何在IntelliJ IDEA中应用@ControllerAdvice?

Java - Scene1 未显示,相同的 Scene2 有效

url - 如何知道站点的查询字符串的所有可能参数是什么?

java - 错误: unreported exception ErrorException; must be caught or declared to be thrown