线程 "main" java.lang.RuntimeException 中的异常:无法编译的源代码 - 找不到符号
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cant find symbol
我是 Java 的新编程人员,我发现了一个我无法解决的错误。我已经多次修改了我的所有代码,但我似乎没有发现任何错误(也可能是我对这门语言没有真正的经验:/)。当尝试 运行 我的代码时,这是控制台向我显示的内容
"Exception in thread "main" java.lang.RuntimeException: 无法编译的源代码 - 找不到符号
符号:变量 TaxReturn
位置:class taxReturnTester ....“
我可以看出错误是因为我的变量 "TaxReturn" 但除了更改首字母大写错误外,我看不出还有什么问题!!
这是我的代码:
package taxreturn;
public class TaxReturn {
public TaxReturn (double anIncome, int aStatus){
income=anIncome;
status = aStatus;
}
public double getTax (){
double tax = 0;
if (status == Single ){
if (income <= Single_Bracket1)
tax = Rate1 * income;
else if ( income <= Single_Bracket2)
tax = Rate1 * Single_Bracket1 + Rate2*(income - Single_Bracket1);
else
tax = Rate1 * Single_Bracket1 + Rate2 * (Single_Bracket2 -
Single_Bracket1) + Rate3 * (income - Single_Bracket2);
else
if (income<= Married_Bracket1)
tax=Rate1 * income;
else if (income <= Married_Bracket2)
tax= Rate1 * Married_Bracket1 + Rate2 * (income -
Married_Bracket1);
else
tax = Rate1 * Married_Bracket1 + Rate2 * ( Married_Bracket2 -
Married_Bracket1) + Rate3 * (income - Married_Bracket2);
}
return tax;
public static final int Single = 1;
public static final int Married = 2;
private static final double Rate1= 0.5;
private static final double Rate2= 0.25;
private static final double Rate3= 0.75;
private static final double Single_Bracket1= 21450;
private static final double Single_Bracket2= 51900;
private static final double Married_Bracket1= 35000;
private static final double Married_Bracket2= 86800;
private double income;
private int status;
import java.util.Scanner;
public class taxReturnTester {
public static void main (String [] args) {
Scanner in = new Scanner (System.in);
System.out.print("Please Enter your Income:");
double income = in.nextDouble();
System.out.print("Please enter S (single) M (Married): ");
String input = in.next();
// CHECK POINT
System.out.println("Check point1");
int status= 0;
if (input.equalsIgnoreCase("s"))
status= TaxReturn.single;
else if (input.equalsIgnoreCase("m"))
status = TaxReturn.married;
else
System.out.println("Wrong Input. Please do it again");
return;
}
}
TaxReturn aTaxReturn = new TaxReturn(income,status);
System.out.println ("The tax is" + aTaxReturn.getTax() );
package taxreturn;
import java.util.Scanner; // on top
public class TaxReturn {
// only one public class per file
public static final int Single = 1;
public static final int Married = 2;
private static final double Rate1= 0.5;
private static final double Rate2= 0.25;
private static final double Rate3= 0.75;
private static final double Single_Bracket1= 21450;
private static final double Single_Bracket2= 51900;
private static final double Married_Bracket1= 35000;
private static final double Married_Bracket2= 86800;
private double income;
private int status;
public TaxReturn (double anIncome, int aStatus){
income=anIncome;
status = aStatus;
}
public double getTax (){
double tax = 0;
if (status == Single ){
if (income <= Single_Bracket1)
tax = Rate1 * income;
else if ( income <= Single_Bracket2)
tax = Rate1 * Single_Bracket1 + Rate2*(income - Single_Bracket1);
else
tax = Rate1 * Single_Bracket1 + Rate2 * (Single_Bracket2 - Single_Bracket1) + Rate3 * (income - Single_Bracket2);
} // added
else
if (income<= Married_Bracket1)
tax=Rate1 * income;
else if (income <= Married_Bracket2)
tax= Rate1 * Married_Bracket1 + Rate2 * (income -
Married_Bracket1);
else
tax = Rate1 * Married_Bracket1 + Rate2 * ( Married_Bracket2 -
Married_Bracket1) + Rate3 * (income - Married_Bracket2);
// not here }
return tax;
} // ends getTax
} // added, ends class
// import java.util.Scanner; not here
class taxReturnTester {
public static void main (String [] args) {
Scanner in = new Scanner (System.in);
System.out.print("Please Enter your Income:");
double income = in.nextDouble();
System.out.print("Please enter S (single) M (Married): ");
String input = in.next();
// CHECK POINT
System.out.println("Check point1");
int status= 0;
if (input.equalsIgnoreCase("s"))
status= TaxReturn.Single; // upcase
else if (input.equalsIgnoreCase("m"))
status = TaxReturn.Married; // upcase
else
{ // added
System.out.println("Wrong Input. Please do it again");
return;
} // added
TaxReturn aTaxReturn = new TaxReturn(income,status);
System.out.println ("The tax is: " + aTaxReturn.getTax() ); // added space
} // ends main
} // ends class
// not out any classes
// TaxReturn aTaxReturn = new TaxReturn(income,status);
// System.out.println ("The tax is" + aTaxReturn.getTax() );
我是 Java 的新编程人员,我发现了一个我无法解决的错误。我已经多次修改了我的所有代码,但我似乎没有发现任何错误(也可能是我对这门语言没有真正的经验:/)。当尝试 运行 我的代码时,这是控制台向我显示的内容
"Exception in thread "main" java.lang.RuntimeException: 无法编译的源代码 - 找不到符号 符号:变量 TaxReturn 位置:class taxReturnTester ....“
我可以看出错误是因为我的变量 "TaxReturn" 但除了更改首字母大写错误外,我看不出还有什么问题!!
这是我的代码:
package taxreturn;
public class TaxReturn {
public TaxReturn (double anIncome, int aStatus){
income=anIncome;
status = aStatus;
}
public double getTax (){
double tax = 0;
if (status == Single ){
if (income <= Single_Bracket1)
tax = Rate1 * income;
else if ( income <= Single_Bracket2)
tax = Rate1 * Single_Bracket1 + Rate2*(income - Single_Bracket1);
else
tax = Rate1 * Single_Bracket1 + Rate2 * (Single_Bracket2 -
Single_Bracket1) + Rate3 * (income - Single_Bracket2);
else
if (income<= Married_Bracket1)
tax=Rate1 * income;
else if (income <= Married_Bracket2)
tax= Rate1 * Married_Bracket1 + Rate2 * (income -
Married_Bracket1);
else
tax = Rate1 * Married_Bracket1 + Rate2 * ( Married_Bracket2 -
Married_Bracket1) + Rate3 * (income - Married_Bracket2);
}
return tax;
public static final int Single = 1;
public static final int Married = 2;
private static final double Rate1= 0.5;
private static final double Rate2= 0.25;
private static final double Rate3= 0.75;
private static final double Single_Bracket1= 21450;
private static final double Single_Bracket2= 51900;
private static final double Married_Bracket1= 35000;
private static final double Married_Bracket2= 86800;
private double income;
private int status;
import java.util.Scanner;
public class taxReturnTester {
public static void main (String [] args) {
Scanner in = new Scanner (System.in);
System.out.print("Please Enter your Income:");
double income = in.nextDouble();
System.out.print("Please enter S (single) M (Married): ");
String input = in.next();
// CHECK POINT
System.out.println("Check point1");
int status= 0;
if (input.equalsIgnoreCase("s"))
status= TaxReturn.single;
else if (input.equalsIgnoreCase("m"))
status = TaxReturn.married;
else
System.out.println("Wrong Input. Please do it again");
return;
}
}
TaxReturn aTaxReturn = new TaxReturn(income,status);
System.out.println ("The tax is" + aTaxReturn.getTax() );
package taxreturn;
import java.util.Scanner; // on top
public class TaxReturn {
// only one public class per file
public static final int Single = 1;
public static final int Married = 2;
private static final double Rate1= 0.5;
private static final double Rate2= 0.25;
private static final double Rate3= 0.75;
private static final double Single_Bracket1= 21450;
private static final double Single_Bracket2= 51900;
private static final double Married_Bracket1= 35000;
private static final double Married_Bracket2= 86800;
private double income;
private int status;
public TaxReturn (double anIncome, int aStatus){
income=anIncome;
status = aStatus;
}
public double getTax (){
double tax = 0;
if (status == Single ){
if (income <= Single_Bracket1)
tax = Rate1 * income;
else if ( income <= Single_Bracket2)
tax = Rate1 * Single_Bracket1 + Rate2*(income - Single_Bracket1);
else
tax = Rate1 * Single_Bracket1 + Rate2 * (Single_Bracket2 - Single_Bracket1) + Rate3 * (income - Single_Bracket2);
} // added
else
if (income<= Married_Bracket1)
tax=Rate1 * income;
else if (income <= Married_Bracket2)
tax= Rate1 * Married_Bracket1 + Rate2 * (income -
Married_Bracket1);
else
tax = Rate1 * Married_Bracket1 + Rate2 * ( Married_Bracket2 -
Married_Bracket1) + Rate3 * (income - Married_Bracket2);
// not here }
return tax;
} // ends getTax
} // added, ends class
// import java.util.Scanner; not here
class taxReturnTester {
public static void main (String [] args) {
Scanner in = new Scanner (System.in);
System.out.print("Please Enter your Income:");
double income = in.nextDouble();
System.out.print("Please enter S (single) M (Married): ");
String input = in.next();
// CHECK POINT
System.out.println("Check point1");
int status= 0;
if (input.equalsIgnoreCase("s"))
status= TaxReturn.Single; // upcase
else if (input.equalsIgnoreCase("m"))
status = TaxReturn.Married; // upcase
else
{ // added
System.out.println("Wrong Input. Please do it again");
return;
} // added
TaxReturn aTaxReturn = new TaxReturn(income,status);
System.out.println ("The tax is: " + aTaxReturn.getTax() ); // added space
} // ends main
} // ends class
// not out any classes
// TaxReturn aTaxReturn = new TaxReturn(income,status);
// System.out.println ("The tax is" + aTaxReturn.getTax() );