I have written a simple Employee class that is suppose to pass the tests that have been given to us but the tests are failing and I can't see why. The methods are doing what they are suppose to be doing as you can see from the main class. This was suppose to be a simple 15 minute exercise but I have no idea why the program isn't passing the tests. Could anyone shed some light for me?
I have included all three classes the Employee, EmployeeTest and the Main.
* Class to represent an employee in an organisation as * part of a payroll application */ package comp125; /** * @author ;a;a;a * */ public class Employee { // the name of the employee private String name_; // the annual salary in dollars private double annualSalary_; // the bank account number private String bankAccountNumber_; /** * Return the weekly pay for this employee * @return the weekly pay in dollars */ public double weeklyPay() { double weekly = (annualSalary_ /52.0); return weekly; } public void setAnnualSalary_(double annualSalary_) { this.annualSalary_ = annualSalary_; } /** * Promote an employee, this adds 10% to the annual salary */ public void promote() { double bonus = (10 * annualSalary_) / 100; annualSalary_ = annualSalary_ + bonus; } public String getName_() { return name_; } public void setName_(String name_) { this.name_ = name_; } public double getAnnualSalary_() { return annualSalary_; } public String getBankAccountNumber_() { return bankAccountNumber_; } public void setBankAccountNumber_(String bankAccountNumber_) { this.bankAccountNumber_ = bankAccountNumber_; } }
* Tests for the Employee class * COMP125 mixed class week 3 2011 */ package comp125; import static org.junit.Assert.*; import org.junit.Test; /** * @author lalala * */ public class EmployeeTest { /** * test that the weekly pay is correct given the * annual salary */ @Test public void testEmployeeWeeklyPay() { Employee emp = new Employee(); // Test a few different salaries emp.setAnnualSalary(50000.0); assertEquals(50000.0/52, emp.weeklyPay(), 0.01); emp.setAnnualSalary(1000.0); assertEquals(1000.0/52, emp.weeklyPay(), 0.01); // What happens if we don't pay anything? emp.setAnnualSalary(0); assertEquals(0.0, emp.weeklyPay(), 0.01); } /** * test the promotion method which should * increase the annual salary by 10% */ @Test public void testEmployeePromotion() { Employee emp = new Employee(); emp.setAnnualSalary(10000.0); // promotion adds 10% emp.promote(); assertEquals(11000.0, emp.getAnnualSalary(), 0.01); } }
package comp125; public class Main { /** * @param args */ public static void main(String[] args) { Employee one = new Employee(); one.setAnnualSalary_(50000.0); one.weeklyPay(); System.out.println("This is weekly pay: " + one.weeklyPay()); System.out.println("This is before promote: " + one.getAnnualSalary_()); one.promote(); System.out.println("This is after promote: " +one.getAnnualSalary_()); } }