gpt4 book ai didi

java - 方法不适用于参数

转载 作者:行者123 更新时间:2023-12-02 07:12:56 26 4
gpt4 key购买 nike

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

1 error found:

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

如何修复它?这是我的测试代码

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)

这就是您尝试调用它的方式:

p1.printData();

您希望 grossPaytax 使用什么值?

说实话,您应该在已经指定了工作时间和小时费率的情况下传递 grossPay 似乎很奇怪,但这是另一回事。最直接的问题是您没有提供方法所需的参数。

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com