-1

エラーがあると表示される理由はわかりませんが、これは正確なエラー メッセージ「Exception in thread "main" java.lang.Error: Unresolved compilation problem:

at org.com1027.cw1.rc00182.Salary.main(Salary.java:8)"

コードは次のとおりです。

package org.com1027.cw1.rc00182;

public class Salary {

/**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
}   
public double salary; //this is the field I have created within the Salary class with type double 
public Salary() { //this is the default constructor
}

public double getsalary() { //Here is the getter for salary class with a return 
    return salary;
}
public double setsalary() { //Here is setter for the salary class with a return 
    return salary;
}

public int calculateTax()
{
    int salary = 16475; //here I am stating the salary using an integer because it is number related
    int taxSalary = 7035; //here I am declaring the result so I can use it later
    int personalAllowance = 9440; //here I am declaring the personal allowance is equal to 9440
    int taxThreshold = 32010; //this is the tax threshold value I have put in for later use when continuing the if statement 
    int lowerTax = 20; //this is the lower tax and because the value holds a decimal I have used a type double. this will come to use when continuing the if statement calculating the tax 
    int higherTax = 40; //this is the higher tax and again used a type double due to the use of a number holding a decimal
    // above are the 6 variables I have created for the if statement below

    if (salary > personalAllowance){ //here I am saying if the salary is more than 9440 (personal allowance) then..     
        taxSalary = salary-personalAllowance; //this is saying the salary (16475) minus personal allowance gives the result (7035) which is the taxable salary
        taxSalary = 0;
    }

    if (taxSalary < taxThreshold) {
        taxSalary = taxSalary * lowerTax;
    }   
      else {
        taxSalary = (taxSalary - taxThreshold) * higherTax + taxThreshold;
      }

}

また、一番下のブレースにエラーがあり、そこに別のものを入れる必要があると言っていますが、どこに欠けているのかわかりません.

4

2 に答える 2

0

コードにバグが含まれています。コンパイラに強制的にコンパイルさせました。しかし、それはできません。それで、実行しようとすると。コンパイルされた Java ファイルが無効であると表示され、停止します。コード内のエラーを検索するつもりはありません。Eclipse のような IDE を使用すると、エラーがどこにあり、何が問題なのかがわかります。

于 2013-10-21T21:56:24.917 に答える