Programming Assignment: Using the
Function Interface and Streams in Java
Student Name: Olukayode Onitilo
University of the People
Course: CS 1102-01 Programming 1 - AY2026-T4
Instructor: Cynthia Hughes
Date: 30/05/2026
Introduction
Modern Java applications frequently process large collections of data. Java 8 introduced
functional programming features such as the Function interface and Streams API, which
allow developers to write concise, readable, and efficient code.
Program Design
The employee dataset contains name, age, department, and salary. The program stores
employee records, transforms them using the Function interface, uses streams for
processing, calculates average salary, and filters employees by age.
Java Program
import [Link];
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 EmployeeManagement {
public static void main(String[] args) {
List<Employee> employees = new ArrayList<>();
[Link](new Employee("John Smith", 28, "IT", 55000));
[Link](new Employee("Sarah Johnson", 35, "HR", 62000));
[Link](new Employee("Michael Brown", 42, "Finance", 75000));
[Link](new Employee("Emily Davis", 31, "Marketing", 60000));
[Link](new Employee("David Wilson", 25, "IT", 50000));
Function<Employee, String> employeeInfo =
employee -> [Link]() + " - " + [Link]();
List<String> employeeDetails = [Link]()
.map(employeeInfo)
.collect([Link]());
double averageSalary = [Link]()
.mapToDouble(Employee::getSalary)
.average()
.orElse(0.0);
List<Employee> filteredEmployees = [Link]()
.filter(employee -> [Link]() > 30)
.collect([Link]());
}
}
Sample Output
Employee Name and Department:
John Smith - IT
Sarah Johnson - HR
Michael Brown - Finance
Emily Davis - Marketing
David Wilson - IT
Average Salary: $60400.0
Employees Older Than 30:
Sarah Johnson (35 years old)
Michael Brown (42 years old)
Emily Davis (31 years old)
Explanation of the Function Interface
The Function interface from [Link] represents a function that accepts one input
and returns one output. In this program, it transforms Employee objects into formatted
strings.
Explanation of Streams
Streams provide a functional approach to processing collections. The program uses map(),
filter(), and average() operations to transform, select, and aggregate data.
Conclusion
The assignment demonstrates how Java's Function interface and Streams API can be used to
efficiently process employee data while improving readability and maintainability.
References (APA 7th Edition)
Bloch, J. (2018). Effective Java (3rd ed.). Addison-Wesley Professional.
Oracle. (2024). Java Platform, Standard Edition documentation: Package [Link].
[Link]
Oracle. (2024). Stream (Java Platform SE Documentation).
[Link]
Sierra, K., & Bates, B. (2022). Head First Java (3rd ed.). O'Reilly Media.