In: Computer Science
Assume that Employee class has method boolean isHighEarner() that returns true if employee's salary is above average and false otherwise. Write an iterative method highEarners that returns the ArrayList<Employee> of all high earners in the given list.
public ArrayList<Employee> highEarners( ArrayList<Employee> list) { } |
Code is Given Below:
===========================
public ArrayList<Employee>
highEarners(ArrayList<Employee> list){
//creating array list Object
ArrayList<Employee> emp=new
ArrayList<Employee>();
//iterating over array list
for(Employee e:list) {
//checking if
employee is higher earner
if(e.isHighEarner())
//adding to array list
emp.add(e);
}
//return array list
return emp;
}
Code Snapshot:
=====================