Newb Java程序員在這裏, 爲什麼這個計算器不計算?Java - 使用If和if else語句的簡單稅計算器
程序應該輸入來自用戶的收入,然後根據計算結果輸出他們的聯邦稅。
聯邦稅收規則: 15%應納稅所得額的第一$四萬五千二百八十二,在接下來的45281 $應納稅所得額(應納稅所得額超過$四萬五千二百八十二高達 90563 $的部分)+ 20.5%,+ 26 %在下49825 $應納稅所得(對應納稅所得的該部分超過$ 90563到 $十四萬〇三百八十八),+
輸入:
輸入標記:85
輸出:
等級是:A
輸入:
輸入標記:110
輸出:
輸入0和100
之間的值輸入:
輸入標記:79.5
輸出:
等級是:B +
輸入:
輸入標記:-10
輸出:
上應納稅所得的下一59612 $(超過$一十四萬○三百八十八上應納稅所得的部分高達 $ 200,000)0和100 29%之間輸入一個值,+ 33%的應納稅收入超過200,000美元。
package practiceproblab4;
import java.util.Scanner;
/**
*
* @author JAVA NEWB
*/
public class PracticeProbLab4 {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter your Income: ");
String In = sc.nextLine();
Double Income = Double.parseDouble(In);
calculateAndPrintTax(Income);
System.out.println("Your taxes are: " + TotalTax);
}
static double calculateAndPrintTax(double Income, double Tax)
{
double tax;
double difftax1;
double difftax2;
double difftax3;
double difftax4;
double TotalTax;
if ((Income >= 45282) && (Income <= 200000))
{
if(Income<=45282)
{
tax = 45282 * 0.15;
TotalTax = tax;
}
else if (Income > 45282 && Income <= 90653)
{
tax = 45282 * 0.15;
difftax1 = (Income - 45282)* .205;
TotalTax = tax + difftax1;
}
else if ((Income >90563) && (Income <= 140388))
{
tax = 45282 * 0.15;
difftax1 = (Income - 45282) * .205;
difftax2 = (Income - 90563) * 0.26;
TotalTax = tax + difftax1 + difftax2;
}
else if ((Income > 140388) && (<= 200000))
{
tax = 45282 * 0.15;
difftax1 = (Income - 45282) * .205;
difftax2 = (Income - 90563) * 0.26;
difftax3 = (Income - 140388) * 0.29;
TotalTax = tax + difftax1 + difftax2 + difftax3;
}
else if ((Income > 200000))
{
tax = 45282 * 0.15;
difftax1 = (Income - 45282) * .205;
difftax2 = (Income - 90563) * 0.26;
difftax3 = (Income - 140388) * 0.29;
difftax4 = (Income - 200000) * 0.33;
TotalTax = tax + difftax1 + difftax2 + difftax3 + difftax4;
}
else ((Income > 200000))
{
tax = 45282 * 0.15;
difftax1 = (Income - 45282) * .205;
difftax2 = (Income - 90563) * 0.26;
difftax3 = (Income - 140388) * 0.29;
difftax4 = (Income - 200000) * 0.33;
TotalTax = tax + difftax1 + difftax2 + difftax3 + difftax4;
return TotalTax;
}
}
}
}
你會得到什麼異常? – ramasCoder
跳出的一個問題是'double TotalTax'在'calculateAndPrintTax'中聲明。這意味着當您嘗試打印'TotalTax'時,在'main'方法中不可見' –
另一個問題:'calculateAndPrintTax'需要2個參數,但您只能在'main'中傳遞一個參數。 –