Periodically, a company processes the retirement of some of its employees. In this question, you will write methods to help the company determine whether an employee is eligible to retire and to process the retirement of employees who wish to retire. You will also analyze the runtime performance of one of the methods that you write.
The Java interface Employee
is implemented by
objects that represent employees. The interface is declared
as follows.
The Company
class is declared as follows.
Two class invariants must be maintained by Company
objects:
The myEmployees
is sorted
(e.g., by employee ID), note that interface Employee
extends
the Comparable
interface.
myTotalSalary
is the total
of all employee salaries.
Company
constructor will establish these invariants as
true initially. Each Company
method must ensure that the
invariants remain true after the method's execution.
RETIRE_AGE
years old.
RETIRE_YEARS
years.
RETIRE_SALARY
.
Write the private Company
method
employeeIsEligible
, which is described as follows.
Method employeeIsEligible
returns a boolean value
that indicates whether the employee represented by parameter
emp
is eligible for retirement, using the rules above.
Complete method employeeIsEligible
below.
Write the Company
method processRetirements
,
which is described as follows. Method processRetirements
has one parameter, claimants
representing all employees
that wish to retire. Assume claimants
is sorted in
ascending order, contains no duplicates, and that all
elements in claimants
are also in private instance variable
myEmployees
. Method processRetirements
removes
from ArrayList myEmployees
only those employees listed in
claimants
that are eligible for retirement and maintains
the two class invariants described above: the ArrayList is maintained in
ascending order and myTotalSalary
is the total of all
salaries of the remaining employees.
Assume that the class used to implement the Employee
interface has an overridden method equals
consistent
with its method compareTo
.
In writing processRetirements
, you may call
method employeeIsEligible
, specified in part (a). Assume
that employeeIsEligible
works as specified, regardless of
what you wrote in part (a).
Complete method processRetirements
below.
processRetirements
. Justify your answer with reference to
the code you wrote in part (b). You will NOT receive full credit if you
do not provide a justification.