Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Payroll{
- public List<Employee> employess = new ArrayList<Employee>();
- public Iterator<Employee> aboveAverageIterator(){
- double sum = 0;
- for(Employee a: employess){
- sum += a.getSalary();
- }
- return new AboveAverageIterator(sum/(employess.size()));
- }
- class AboveAverageIterator implements Iterator<Employee>{
- private double average;
- private Employee cur = null;
- private final Iterator<Employee> it = employess.iterator();
- public AboveAverageIterator(double average){
- this.average = average;
- this.reach_next();
- }
- private void reach_next(){
- boolean flag = false;
- Employee t = null;
- while(!flag && it.hasNext()){
- t = it.next();
- if(t.getSalary() > average)
- flag = true;
- }
- cur = flag ? t : null;
- }
- public boolean hasNext(){
- return cur != null;
- }
- public Employee next(){
- Employee temp = cur;
- this.reach_next();
- return temp;
- }
- public void remove(){
- throw new UnsupportedOperationException();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement