이 h.getNetYearlyIncome()에서 실패하고 5k가 너무 높습니다. 나는 하루 종일 그것에 종사하고 있고 그것을 이해할 수 없다.메서드를 호출하고 로컬 변수를 반환하는 데 차이점은 무엇입니까?
public void testSalariedEmployeeMakingOver100K() {
SalariedEmployee h = new SalariedEmployeeImpl("John", "Doe", "Mechanical Turk", 1111, 9166.75);
assertEquals(h.getFirstName(), "John");
assertEquals(h.getLastName(), "Doe");
assertEquals(h.getJobTitle(), "Mechanical Turk");
assertEquals(h.getID(), 1111);
assertEquals(h.getMonthlySalary(), 9166.75, 0.005);
assertEquals(h.getGrossYearlyIncome(), 9166.75*12, 0.005);
assertEquals(h.getTaxableIncome(), h.getGrossYearlyIncome(), 0.005);
assertEquals(h.getTaxesWithheld(), 15000.25, 0.005);
assertEquals(h.getNetYearlyIncome(), h.getGrossYearlyIncome()-h.getTaxesWithheld(), 0.005);
}
public class SalariedEmployeeImpl extends EmployeeImpl implements
SalariedEmployee {
String first_name;
String last_name;
String job_title;
int id;
double monthly_salary = 0.0;
double yearlyIncome = 0.0;
double taxableIncome = 0.0;
double netIncome = 0.0;
double taxesWitheld = 0.0;
double over100k = 0.0;
double over50k= 0.0;
SalariedEmployeeImpl(String first_name, String last_name, String job_title,
int id, double monthly_salary) {
this.first_name = first_name;
this.last_name = last_name;
this.job_title = job_title;
this.id = id;
this.monthly_salary = monthly_salary;
}
public String getFirstName() {
return first_name;
}
public String getLastName() {
return last_name;
}
public String getJobTitle() {
return job_title;
}
public int getID() {
return id;
}
public double getGrossYearlyIncome() {
yearlyIncome = (monthly_salary * 12);
return yearlyIncome;
}
public double getTaxableIncome() {
taxableIncome = (monthly_salary*12);
return taxableIncome;
}
public double getTaxesWithheld() {
double over100k = 0.0;
double over50k= 0.0;
if(taxableIncome>100000.0){
over100k = taxableIncome -100000.0;
taxableIncome -=over100k;
}
if(taxableIncome >50000.0 && taxableIncome <=100000.0){
over50k = taxableIncome-50000.0;
taxableIncome -=over50k;
}
taxesWitheld = taxesWitheld + (.15 * over50k)+(.25 * over100k)+(.1*taxableIncome);
return taxesWitheld ;
}
public double getNetYearlyIncome() {
return yearlyIncome-taxesWitheld;
}
public double getMonthlySalary() {
return monthly_salary;
}
public void setMonthlySalary(double salary) {
this.monthly_salary = salary;
}
}
@ BheshGurung이 말하는 것은 사실입니다. 통화를 나타 내기 위해'double '을 사용하면, 어느 시점에서 정밀도를 잃거나 반올림하여 물릴 것입니다. 그러나 그것은 당신의 문제를 일으키는 것이 아닙니다. – sigpwned