I have the following class diagram.
I need to output a toString that looks like " James, Sid (1234): Director at £100000.0 (£29822.0 tax) and is eligible for bonus "
However i cannot find a way to print out the part where it return whether an employee is eligible for bonus or not.
Any help is much appreciated!
Here is my attempt to create the class.
package org.com1027.formative.ye00036;
public class Employee {
//Class Field(s)
private int id = 0;
private String forename = null;
private String surname = null;
private Salary salary = null;
private CompanyPosition companyPosition = null;
//Parameterised constructor using all fields, allowing creation of objects
public Employee(int id, String forename, String surname, Salary salary, CompanyPosition companyPosition) {
super();
this.id = id;
this.forename = forename;
this.surname = surname;
this.salary = salary;
this.companyPosition = companyPosition;
}
//Getters-Accessors
//Returns the employee's ID
public int getId() {
return id;
}
//Returns the employee's Forename
public String getForename() {
return forename;
}
//Returns the employee's Surname
public String getSurname() {
return surname;
}
//Returns the employee's Salary
public Salary getSalary() {
return salary;
}
//Returns the employee's Company Position
public CompanyPosition getPositionName() {
return companyPosition;
}
//Checks if an employee is eligible for bonus
public boolean eligibleForBonus(){
if (salary.getSalary() >= 40000)
return true;
else
return false;
}
@Override
public String toString() {
return getForename() + ", " + getSurname() + "(" + getId() +
"): " + getPositionName() + "at " + salary.getSalary() + " (" + salary.calculateTax() + ") and is ";
}
}
