申請ステータスが独身の人の税金を計算するこの方法があります。しかし、これを for ループに変換したり、while ループの代わりに Array を使用したりするのに苦労しています。コードを簡略化して見栄えを良くしたい。助言がありますか?
public void calculateTax()
{
//The constant fields for the tax rate
final double TAXRATE_10 = 0.1; //10%
//This is the tax rate percent on the tax 15%
final double TAXRATE_15PERCENT = 0.15;
//This is the tax rate percent on the tax 25%
final double TAXRATE_25PERCENT = 0.25;
//This is the tax rate percent on the tax 28%
final double TAXRATE_28PERCENT = 0.28;
//This is the tax rate percent on the tax 33%
final double TAXTRATE_33PERCENT = 0.33;
//This is the tax rate percent on the tax 35%
final double TAXRATE_35PERCENT = 0.35;
//constant numbers for tax boundaries.
final int NOTRICH = 8700;
final int MIDDLECLASS = 35350;
final int SORTOFRICH = 85650;
final int RICH = 178650;
final int FORSURERICH = 388350;
//Variables for taxable income, and tax calculation.
long taxableIncome = income - deduction -(numberOfExemption * VAlUEOFEXEMPTION);
double cumulatedTax = 0;
//Calculate the Tax
while(taxableIncome != 0)
{
if(taxableIncome > FORSURERICH)
{
cumulatedTax += ((taxableIncome-FORSURERICH) * TAXRATE_35PERCENT);
taxableIncome = (long)FORSURERICH;
}
else if(taxableIncome > RICH)
{
cumulatedTax += ((taxableIncome-RICH) * TAXTRATE_33PERCENT);
taxableIncome = (long)RICH;
}
else if(taxableIncome > SORTOFRICH)
{
cumulatedTax += ((taxableIncome-SORTOFRICH) * TAXRATE_28PERCENT);
taxableIncome = (long)SORTOFRICH;
}
else if(taxableIncome > MIDDLECLASS)
{
cumulatedTax += ((taxableIncome-MIDDLECLASS) * TAXRATE_25PERCENT);
taxableIncome = (long)MIDDLECLASS;
}
else if(taxableIncome > NOTRICH)
{
cumulatedTax += ((taxableIncome-NOTRICH) * TAXRATE_15PERCENT);
taxableIncome = (long)NOTRICH;
}
else
{
cumulatedTax += ((taxableIncome) * TAXRATE_10);
taxableIncome = 0;
}
}