方法不适用于参数 [英] Method not applicable for arguments

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

问题描述

我正在尝试创建一个测试器类,但是这样做时出现了一个错误,指出:

I'm trying to create a tester class, but in doing so I have gotten an error which states:

1 error found:

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

我该如何解决?这是我的测试人员代码

How do I fix it? This my tester code

PayCalculator p1 = new PayCalculator();
    p1.setHourlyRate(8.25);
    p1.setHoursWorked(45.0);    
    p1.printData();

我的主要代码

{
  private double hourlyRate;
  private double hoursWorked;


  public PayCalculator()
  {
    hourlyRate = 0.0;
    hoursWorked = 0.0;
  }

  /**
   * 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(double grossPay, double tax)
  {
    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(grossPay));
    System.out.println("Net Pay: " + calculateNetPay(grossPay, tax));
  }
}

推荐答案

是的.这是方法声明:

public void printData(double grossPay, double tax)

这就是您要如何称呼它:

And here's how you're trying to call it:

p1.printData();

您希望grossPaytax使用什么值?

说实话,您应该已经指定了工作时间和小时费率而必须通过grossPay,这似乎很奇怪,但这是另一回事.最直接的问题是您没有提供方法所需的参数.

To be honest it seems odd that you should have to pass in grossPay having already specified the hours worked and hourly rate, but that's a different matter. The most immediate problem is that you're not providing the arguments your method requires.

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

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