2013-10-16 41 views
0

確定。所以情況就是這樣。在我的課堂中有一個calculateTax方法,如下所示。變化領域的可回收局部變量在if語句

但我意識到,我已經犯了大錯。實際上,在課程開始時,「稅收」就是作爲一個領域創造的。

private double tax;

這實際上應該是一個變量!

但是,當我創建它作爲方法的局部變量public double calculateTax(double tax)它的工作原理,但是當我跑我的測試反對他們失敗了。我得到的消息

The method calculateTax(double) in the type Salary is not applicable for the arguments()

所以我要去哪裏錯了?

如何建立稅收變量(仍然可以退還)不改變方法的名稱? 「calculateTax」方法需要保持原樣。那麼我在哪裏以及如何創建「稅收」變量?提前致謝!

public double calculateTax() { 

if (this.salary <= personalAllowance) { // If the salary is less 
    // £9440 (personal allowance) and below then no tax will be applied. 

} 

else if (this.salary <= taxThreshold) { // Else if the salary is less than or equal to the 
    // tax threshold then do the following: 
    double taxableSalary = this.salary - personalAllowance; // Salary take away the personal allowance 
    // equals the taxable salary. 
    this.tax = taxableSalary * 0.2; // The tax equal the taxable salary * 0.2 (20%) 
} 

else if (this.salary > 32010) { 

    double basicRate = taxThreshold * 0.2; // The basic rate tax is the tax threshold * 0.2 
    double difference = this.salary - taxThreshold; // The difference is the salary - the tax threshold 
    double highTax = difference - personalAllowance; // The high tax to be calculated is the difference 
    // take away personal allowance. 
    double highRate = highTax * 0.4; // The high rate tax is the high tax * the high tax value (40%) 

    this.tax = highRate + basicRate; // Total tax is the high rate tax (40%) + the basic rate tax (20%) 

} 
return tax; 

回答

0

您的稅收變量很好。

編譯器認爲你calculateTax()方法需要一個參數,雙,佔工資。 (我想 - 可能是稅率?)例如calculateTax(56789.12);

我沒有看到你發佈的代碼,但東西是不完整的。