-1

我不知道为什么它说我有错误,但这是确切的错误消息“线程“main”java.lang.Error中的异常:未解决的编译问题:

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

您的 setSalary() 是否应该不做任何事情,或者是否有您忘记包含的附加代码?

一般来说,setter 应该如下所示,但显然你可以让它返回一个值或布尔值:

public void setsalary(double salary) {  // setSalary would have been more readable
    this.salary = salary;
}

编辑:正如其他人指出的那样,您缺少一个班级括号。我已经为它提供了一个可能的位置。

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

     return taxSalary;  // <--- missing a return statement here
  }

} // <--- 这里缺少一个类右括号。

于 2013-10-21T22:02:21.717 回答
0

您的代码包含错误。你强迫编译器编译它。然而它不能。因此,当您尝试运行它时。它会停下来并说编译的 Java 文件无效。我不会在代码中搜索您的错误。使用像 Eclipse 这样的 IDE,它会告诉您错误在哪里以及问题出在哪里。

于 2013-10-21T21:56:24.917 回答