0% found this document useful (0 votes)
3 views2 pages

Java Function Streams Assignment

Uploaded by

Joseph Njovu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Java Function Streams Assignment

Uploaded by

Joseph Njovu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Java Function Interface and Streams -

Employee Processing Assignment


Java Function Interface and Streams - Employee Processing Assignment

INTRODUCTION
This project demonstrates Java Function interface and Streams API.

JAVA CODE

import [Link].*;
import [Link];
import [Link];

class Employee {
private String name;
private int age;
private String department;
private double salary;

public Employee(String name, int age, String department, double salary) {


[Link] = name;
[Link] = age;
[Link] = department;
[Link] = salary;
}

public String getName() { return name; }


public int getAge() { return age; }
public String getDepartment() { return department; }
public double getSalary() { return salary; }
}

public class EmployeeStreamDemo {

public static void main(String[] args) {

List<Employee> employees = [Link](


new Employee("John", 28, "IT", 50000),
new Employee("Mary", 35, "HR", 60000),
new Employee("Peter", 40, "Finance", 75000),
new Employee("Susan", 25, "IT", 45000),
new Employee("David", 32, "Marketing", 55000)
);

Function<Employee, String> nameDeptFunction =


e -> [Link]() + " - " + [Link]();

List<String> nameDeptList = [Link]()


.map(nameDeptFunction)
.collect([Link]());

double averageSalary = [Link]()


.mapToDouble(Employee::getSalary)
.average()
.orElse(0.0);

[Link](nameDeptList);
[Link](averageSalary);
}
}

OUTPUT
Employee Name-Department List:
John - IT
Mary - HR
Peter - Finance
Susan - IT
David - Marketing

Average Salary: 58000.0

CONCLUSION
Demonstrates functional programming in Java using Function interface and Streams.

You might also like