所以我真的很困惑我做错了什么,我知道我犯了一个愚蠢的错误,但我真的需要帮助。如果有人可以给我一个提示,将不胜感激。我正在编写一些代码来计算一个人的收入,但由于某种原因,它只是出现了信用。
public class TaxReturn
{
private double income;
private double deductions;
private int numberofExemptions;
private double credits;
private double tax;
public TaxReturn(double salary, double deductable, int exempt,
double creditable)
{
tax = 0;
income = salary;
deductions = deductable;
numberofExemptions = exempt;
credits = creditable;
}
public void calculateTax()
{
final double exempt = 3800;
double exemption = numberofExemptions * exempt;
double taxableIncome = income - deductions - exemption;
final double rate_10 = 0.1;
final double rate_15 = 0.15;
final double rate_25 = 0.25;
final double rate_28 = 0.28;
final double rate_33 = 0.33;
final double rate_35 = 0.35;
final double rate_395 = 0.395;
final double income1 = 8925;
final double income2 = 36250;
final double income3 = 87850;
final double income4 = 183250;
final double income5 = 398350;
final double income6 = 400000;
while(taxableIncome != 0)
{
if(taxableIncome > income6)
{
tax = (taxableIncome - income6) * rate_395;
}
else if(taxableIncome > income5)
{
tax = (taxableIncome - income5) * rate_35;
}
else if(taxableIncome > income4)
{
tax = (taxableIncome - income4) * rate_33;
}
else if(taxableIncome > income3)
{
tax = (taxableIncome - income3) * rate_28;
}
else if(taxableIncome > income2)
{
tax = (taxableIncome - income2) * rate_25;
}
else if(taxableIncome > income1)
{
tax = (taxableIncome - income1) * rate_15;
}
else
{
tax = (taxableIncome) * rate_10;
}
}
}
public int printTaxReturn()
{
int amount = (int) ((int)Math.ceil(tax) - credits);
return amount;
}
}
这是我用来测试代码的
public class TaxReturnTester
{
public static void main(String[] args)
{
TaxReturn tax = new TaxReturn(80500.5, 20000.00, 3, 5000.00);
System.out.println(tax.printTaxReturn());
}
}