在类型的方法不适用于参数 [英] the method in type not applicable for the arguments

查看:208
本文介绍了在类型的方法不适用于参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误信息:

找到

2的错误:

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

错误:在类型PayCalculator的方法calculateNetPay(双,双)不适用的参数()

你能告诉我怎样做才能解决这个问题?

 公共类PayCalculator
{
  私人双hourlyRate;
  私人双hoursWorked;  / **
   *两个参数的构造函数
   *添加hourlyRate和hoursWorked
   * @参数时薪
   * @参数的工作时间
   * /
  公共PayCalculator(双aHourlyRate,双aHoursWorked)
  {
    hourlyRate = aHourlyRate;
    hoursWorked = aHoursWorked;
  }  / **
   *设置每小时收费
   * @返回hourlyRate
   * /
  公共无效setHourlyRate(双aHourlyRate)
  {
    hourlyRate = aHourlyRate;
  }  / **
   *获取每小时收费
   * @参数hourlyRate
   * /
  公共双getHourlyRate()
  {
    返回hourlyRate;
  }  / **
   *设置工作时间
   * @返回hoursWorked
   * /
  公共无效setHoursWorked(双aHoursWorked)
  {
    hoursWorked = aHoursWorked;
  }  / **
   *得到工作时间
   * @参数工时
   * /
  公共双getHoursWorked()
  {
    返回hoursWorked;
  }  公共布尔workedOvertime()
  {
    如果(hoursWorked→40)
    {
      返回true;
    }
    其他
    {
      返回false;
    }
  }  公共双numHoursOvertime()
  {
    如果(hoursWorked→40)
    {
      返回hoursWorked - 40;
    }
    其他
    {
      返回0;
    }
  }  公共双calculateGrossPay()
  {
    如果(hourlyRate< = 10.25)
    {
      如果(hourlyRate< = 40)
        返回hourlyRate * hoursWorked;
    }
    其他
    {
      双grossPay =((40 * hourlyRate)+((hourlyRate * 2)* hoursWorked - 40));
      返回grossPay;
    }    如果(hoursWorked< = 60)
    {
      返回hourlyRate * hoursWorked;
    }
    其他
    {
      返回60 * hourlyRate;
    }
  }  公共双determineTaxRate(双grossPay)
  {
    如果(grossPay> = 800)
    {
      避免双重征税= 0;
      税= grossPay * 0.37;
      返回税;
    }
    否则,如果(grossPay> = 400)
    {
      避免双重征税= 0;
      税= grossPay * 0.22;
      返回税;
    }
    其他
    {
      避免双重征税= 0;
      税= grossPay * 0.12;
      返回税;
    }
  }  公共双calculateNetPay(双grossPay,避免双重征税)
  {
    双calculateNetPay = grossPay - 税;
    返回calculateNetPay;
  }  公共无效printData()
  {
    的System.out.println(工作小时数:+ hoursWorked);
    的System.out.println(每小时收费:+ hourlyRate);
    的System.out.println(超时工作时数:+ numHoursOvertime());
    的System.out.println(加班?+ workedOvertime());
    的System.out.println(工资总额+ calculateGrossPay());
    的System.out.println(税率+ determineTaxRate());
    的System.out.println(净工资+ calculateNetPay());
  }}


解决方案

您在呼唤

  determineTaxRate()

但你的方法被定义为这样的:

 公共双determineTaxRate(双grossPay)
{

同样的,你的其他错误。你需要一个双击传递给该方法。像这样的:

  determineTaxRate(calculateGrossPay())

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

}

解决方案

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

这篇关于在类型的方法不适用于参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆