[英]Method not applicable for arguments
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();
my main code 我的主要代码
{
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));
}
}
Well yes. 嗯,是。 Here's the method declaration:
这是方法声明:
public void printData(double grossPay, double tax)
And here's how you're trying to call it: 以下是您试图调用它的方式:
p1.printData();
What values do you expect to be used for grossPay
and tax
? 您希望将什么价值用于
grossPay
和tax
?
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. 说实话,你应该通过已经指定工作小时数和小时费率的
grossPay
似乎很奇怪,但这是另一回事。 The most immediate problem is that you're not providing the arguments your method requires. 最直接的问题是您没有提供您的方法所需的参数。
Your method expects two values grossPay
and tax
: 您的方法需要两个值
grossPay
和tax
:
public void printData(double grossPay, double tax)
But you are not providing grossPay
and tax
to it when calling it : 但是,在调用它时,您不会向它提供
grossPay
和tax
:
p1.printData();
Include the value of grossPay
and tax
when calling your method and it will work fine like : 在调用方法时包括
grossPay
和tax
的值,它将正常工作:
p1.printData(123.00,2.5);
Definition of your method is: 您的方法的定义是:
public void printData(double grossPay, double tax)
It expects call with two double arguments whereas you are calling with no argument: 它期望使用两个双参数调用,而您调用时不带参数:
p1.printData();
Pass double arguments to printData(44.85d, 77.56d)
将双参数传递给
printData(44.85d, 77.56d)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.