2017-03-26 7 views
-3

私はJavaで新しいプログラミングをしていますが、私は解決できなかったエラーを発見しました。私はすべてのコードを何度も改訂しましたが、私は間違いを見つけていないようです(これは私が実際に言語に慣れていない可能性もあります)。私のコードを実行しようとすると、これはコンソールが私にスレッド "main"の例外java.lang.RuntimeException:コンパイル不可能なソースコード - シンボルが見つかりません

「スレッドでの例外 『を示したものですメインの』 java.lang.RuntimeException: - :変数TaxReturn 場所:クラス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()); 
+0

あなたが '' taxReturnTester –

+0

であなたの 'TaxReturn'はそんなにありがとうインポートしていません! – Monique

答えて

0
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()); 
+1

コードのみの回答を投稿しないでください。あなたの答えにいくつかの説明を追加してください、それは将来の訪問者のために役立つでしょう。 – Shashanth

関連する問題