[英]the method in type not applicable for the arguments
我收到此錯誤消息:
發現2個錯誤:
錯誤:PayCalculator 類型中的方法determineTaxRate(double) 不適用於參數()
錯誤:PayCalculator 類型中的方法 calculateNetPay(double, double) 不適用於參數 ()
你能告訴我該怎么做才能解決這個問題嗎?
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());
}
}
你在打電話
determineTaxRate()
但是您的方法定義為:
public double determineTaxRate(double grossPay)
{
與您的其他錯誤相同。 您需要將double
傳遞給該方法。 比如這個:
determineTaxRate(calculateGrossPay())
您尚未為從printData()
方法調用的方法指定參數,例如:
System.out.println("Net Pay: " + calculateNetPay());
您正在使用 0 個參數調用calculateNetPay()
,在您指定的方法定義中,它需要 2 個雙參數。
public double calculateNetPay(double grossPay, double tax) { ... }
這同樣適用於您遇到的其他錯誤。
你的方法用一個參數定義。但你沒有傳遞任何參數。
對於calculateNetPay(),您也在做同樣的事情。
你已經像這樣聲明了你的方法:
public double determineTaxRate(double grossPay)
然后像這樣調用它:
determineTaxRate()
顯然,您在調用該方法時錯過了一個參數
通過確定稅收率(someDoubleVar)解決這個問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.