Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

java - the method in type not applicable for the arguments

I am getting this error message:

2 errors found:

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 ()

Can you tell me what to do to fix this?

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());
    }

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are calling

determineTaxRate()

But your method is defined as this:

public double determineTaxRate(double grossPay)
{

Same with your other error. You need to pass a double to the method. Such as this:

determineTaxRate(calculateGrossPay())

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...