
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;

/*
 * A. Create Employee class with the following fields: id, name, salary, department
B. Create a stream of employee objects
C. print employee of particular department
D. filter employee whose salary greater than 5000$
E. find the average salary of employee
F. sort the employees based on name
G. sort the employees on department  and then sort by their name.

 */

/**
 * @Anil Mandal
 */
public class StreamHO {
    public static void main(String[] args) {
        
        List<Employee> employees = new ArrayList<>();
        employees.add(new Employee(1, "Ram Bilas", 1000.5, "hawaldar"));
        employees.add(new Employee(2, "Saab se bada don", 800000.0, "Mumbai ka bhai"));
        employees.add(new Employee(3, "dhanya bhai", 2000.0, "Mumbai ka bhai"));
        employees.add(new Employee(4, "chota chetan", 6000000.0, "Mumbai ka bhai"));
        employees.add(new Employee(5, "Alpha", 3000.0, "science"));
        employees.add(new Employee(6, "Beta", 7000.0, "science"));
        
        Stream empStream;
        
        System.out.println("--------------**All Employees**-----------");
        System.out.println(employees);
        
        System.out.println("\n\n--------------**Employees of Particular Department**-----------");
        empStream = employees.stream();
        Predicate<Employee> filterByDept = (x)->x.department == "Mumbai ka bhai";
        empStream.filter(filterByDept).forEach((x) -> System.out.println(x));
       
        System.out.println("\n\n--------------**Employees with salary > 5000**-----------");
        empStream = employees.stream();
        Predicate<Employee> filterSalary = (x)->x.salary > 5000.0;
        empStream.filter(filterSalary).forEach((x) -> System.out.println(x));
        
        
        
        //need to do
        /*
        E. find the average salary of employee
        F. sort the employees based on name
        G. sort the employees on department  and then sort by their name.
        */    
    }
}

class Employee{
    Integer id;
    String name;
    Double salary;
    String department;
    
    Employee(Integer id, String name, Double salary, String department){
        this.id = id;
        this.name = name;
        this.salary = salary;
        this.department = department;
    }
    
    @Override
    public String toString(){
        return "{id: " + this.id + " | name: " + this.name + " | salary: " + this.salary + " | department: " + this.department + "}";
    }
    
    
}
@@ -1881,205 +1881,1145 @@
     
-%0A        //need to do%0A        /*%0A        E. find the average salary of employee%0A        F. sort the employees based on name%0A        G. sort the employees on department  and then sort by their name.
+System.out.println(%22%5Cn%5Cn--------------**Average salary of employees**-----------%22);%0A        empStream = employees.stream();%0A        ToDoubleFunction%3CEmployee%3E getDouble = x -%3E x.salary; %0A        double average = empStream.mapToDouble(getDouble).average().getAsDouble();%0A        System.out.println(%22The average salary is: $%22 + average);%0A        %0A        %0A        System.out.println(%22%5Cn%5Cn--------------**Sort Employeed Based Name**-----------%22);%0A        Comparator%3CEmployee%3E nameComparer = (e1, e2)-%3E e1.name.compareTo(e2.name);%0A        empStream = employees.stream();%0A        System.out.println(%0A                empStream%0A                .sorted(nameComparer)%0A                .collect(Collectors.toList())%0A        );%0A        %0A        System.out.println(%22%5Cn%5Cn--------------**Sort Employeed Based on Department then by Name**-----------%22);%0A        Comparator%3CEmployee%3E deptComparer = (e1, e2)-%3E e1.department.compareTo(e2.department);%0A        empStream = employees.stream();%0A        System.out.println(%0A                empStream%0A                .sorted(deptComparer.thenComparing(nameComparer))%0A                .collect(Collectors.toList())
 %0A   
@@ -3027,11 +3027,10 @@
     
-*/ 
+);
    %0A
@@ -3528,9 +3528,10 @@
   %0A    %0A
-
 %7D
+%0A

Update StreamHO.java