Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is there a difference between invoking a method and returning a local variable?
    primarykey
    data
    text
    <p>fails at h.getNetYearlyIncome(), seems to be 5k too high. I have been working on it all day and cannot figure it out.</p> <p>Why is h.getNetYearlyIncome()= h.getGrossYearlyIncome() - h.getTaxesWithheld() not equal to yearlyIncome-taxesWitheld</p> <pre><code>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&gt;100000.0){ over100k = taxableIncome -100000.0; taxableIncome -=over100k; } if(taxableIncome &gt;50000.0 &amp;&amp; taxableIncome &lt;=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; } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload