2013-10-21 97 views
-1

我不知道为什么它说我有一个错误,但这是确切的错误信息”线程中的异常“main”java.lang.Error:Unresolved compilation problem :“Exception in thread”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; 
     } 

} 

还说我对大括号的错误就在底部说我需要摆在那里一个又一个,但我不能找到它遗失哪里从。

+0

这意味着你正试图运行无法编译的代码,这是你永远不应该做的。取而代之的是先编译。仔细查看编译错误,并在运行该程序之前修复这些错误。 –

+0

看起来像一个介绍编程任务。你的设置和获得的方法是一样的......但修复:) – dspiegs

+0

你错过了关闭'}'类 – Simiil

回答

0

你的setSalary()是否应该做任何事情或者是否有额外的代码,你忘了包含它?

一般二传手应该如下,但很明显,你可以把它返回一个值或一个布尔值:

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 
    } 

} // < ---缺少类关闭括号。

+0

我真的不知道我在做什么说明说。我做你说的话。从来没有做过编程,所以请不要评论我哈哈 – user2904879

0

您的代码包含错误。你迫使编译器编译它。但它不能。所以当你试图运行它。它会停止并说编译的Java文件无效。我不打算在代码中搜索你的错误。使用像Eclipse这样的IDE,它会告诉你你的错误在哪里以及是什么问题。

+0

昨天晚上我开始编程之前从来没有做过编程,它使我疯狂,而且已经在使用eclipse。它说我需要包括一个支架,但我不知道在哪里 – user2904879

相关问题