理论上,不同层次的收入按不同的百分比征税。前 50k 的 10%,接下来 50k 的 15%,超过 100k 的 25%。
public double getTaxesWithheld() {
if (taxableIncome >= 100000.0) {
taxesWitheld = taxesWitheld+ (.25 * (taxableIncome - 100000.0));
taxableIncome = taxableIncome - 100000.0;
} else {
if (taxableIncome >= 50000.0 && taxableIncome <= 100000.0) {
taxesWitheld = taxesWitheld + (.15 * (taxableIncome - 50000.0));
taxableIncome = taxableIncome - 50000.0;
} else {
if (taxableIncome < 50000.0) {
taxesWitheld = taxesWitheld + (.1 * (taxableIncome - 25000.0));
}
}
if (taxableIncome <= 0) {
return 0.0;
}
}
return taxesWitheld;
}
测试用例1:@Test 构造函数值(first_name、last_name、job_title、id、monthly_salary)
public void EmployeeMakingBetween50Kand100K() {
Employee h = new EmployeeImpl("Jon", "Smith", "Miner", 2222, 6166.75);
assertEquals(h.getMonthlySalary(), 6166.75, 0.005);
assertEquals(h.getGrossYearlyIncome(), 6166.75*12, 0.005);
assertEquals(h.getTaxableIncome(), h.getGrossYearlyIncome(), 0.005);
assertEquals(h.getTaxesWithheld(), 8600.15, 0.005);
assertEquals(h.getNetYearlyIncome(), h.getGrossYearlyIncome()-h.getTaxesWithheld(), 0.005);
}
不会处理 taxWithheld(), 8600.15, 0.005