我正在编写这个程序来计算不同税级的总税额,当输入哨兵数据时,我必须将所有税额相加。我的问题是如何添加我的程序输出的所有税款。这是代码:
import java.util.Scanner;
public class TaxIncome {
public static void main(String[] args) {
Scanner kbd = new Scanner (System.in);
final double fedtax1 = 0.10; // Tax rates
final double fedtax2 = 0.15;
final double fedtax3 = 0.33;
final double taxbracket1 = 15000; // Tax Brackets
final double taxbracket2 = 60000;
final double maxtax1 = 1500; // Max tax on brackets
final double maxtax2 = 8250;
while(true){
System.out.println("Please input the income, type a negative number to end");
double income = kbd.nextDouble();
double totaltax = 0;
double sumOftotaltax = 0;
if(income <= taxbracket1)
totaltax = income * fedtax1;
else if (income <= taxbracket2 && income > taxbracket1)
totaltax = ((income-taxbracket1)* fedtax2)+ maxtax1;
else if (income > taxbracket2)
totaltax = ((income-taxbracket2)*fedtax3)+maxtax2;
System.out.println("The total tax is $" +totaltax);
if (income < 0) break;
sumOftotaltax = totaltax;
System.out.println("The total of the taxes is $" +sumOftotaltax);
}
}
}