Skip to main content
Dat 2nd Sem Fall 2025
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

CodeLab

  • This CodeLab exercise is designed to help you practice the concepts you have learned in the Java Deep Dive I module on day-1. You will be working on a series of tasks that involve Java Streams, Java Time API, and Lambdas. You will also practice using Git and Github. Make an effort to use Git on the command line as much as possible (Git Bash / Terminal) to get more comfortable with it. Check Git help in the bottom of this page for more information.
  • The exercise comes in 2 versions:
    • A simpler version with to train mainly lambda and streams.
    • A more complex version with focus on the Time API

Instructions

1. Team up

  1. Team up in pairs so you can learn from each other.

Version 1 (Light version)

  • Imagine you have a collection of employees, each with attributes like name, age, department, and salary. Your task is to perform various data analysis tasks using lambda expressions and streams.

2. Setup the development environment

3.1 Create the Employee Class with attributes: name (String), birthDate (LocalDate), department (String), and salary (double).

3.2 Create a collection of Employee objects to work with.

3.3 Data Analysis:

Implement the following tasks using lambda expressions and streams:

  • Find the employee with the highest salary.
  • Count the number of employees in each department.
  • Group employees by department and calculate the average salary for each department.
  • Filter and display employees whose salary is above a certain threshold.
  • Calculate the age of each employee based on their birthdate.
  • Calculate the average age of all employees.
  • Find the three oldest employees.
  • Filter and display employees who have birthdays in a specific month.
  • Group employees by birth month and display the count of employees in each group.
  • List all employees who has a birthday in the current month.
  • Create a method to sort employees based on different criteria, such as age, salary, or name.

Check these hints for explanations of the date and time API in Java 8.

Version 2 (with Time API)

2. Setup the development environment

  1. Fork Flight data Repo into your own Github account. The Flight data Repo is a simple application that reads a CSV file with flight data and calculates the total flight time for each airline.
  2. Open the project in IntelliJ IDEA
  3. Make sure that the project builds and runs without errors. If you have issues, make sure that all Maven dependencies are downloaded and that the project SDK is set to Java 17.

3. Get aqainted with the code

  1. Run the application (find the Main class in FlightReader) and see how it works
  2. Look at the code and understand how it works. How does the duration of the flights get calculated and more? You might want to know more about the Lombok library and how it is used in the code to simplify getters, setters etc.
  3. Look at the json file and discuss the structure of the data with your team
  4. Make sure that the data in the json file correlates with the data printed in the console
  5. Find the unit-test and run it.
  6. See if you can understand the test and what it is testing. Could it be improved?

4. Identify tasks, break them down and prioritize

Inspiration for first round tasks:

  1. Add a new feature (e.g. calculate the total flight time for a specifc airline. For example, calculate the total flight time for all flights operated by Lufthansa)

5. Start working on the tasks (round 1)

  1. Create a branch off the main branch for each task. Call it something like round-1
  2. Work on the tasks together using pair programming. Let one person code and the other navigate and ask questions

6. Merge the code

  1. Merge the round-1 branch into the main branch:
    • On the round-1 branch: add the changes to the staging area, then you commit the changes
    • Checkout the main branch and merge the round-1 branch into it.
  2. Remove the round-1 branch
  3. Add, commit, and push the changes from main to the remote repository and let the other team member pull the changes. Make sure that the code works as expected
  4. Check that both team members have the latest changes

7. Repeat

  1. Identify the next tasks (get inspiration from the list below)
  2. Repeat steps 5-7 for the next tasks and swap roles each round

Inspiration for tasks

  1. Add a new feature (e.g. calculate the average flight time for a specific airline. For example, calculate the average flight time for all flights operated by Lufthansa)
  2. Add a new feature (make a list of flights that are operated between two specific airports. For example, all flights between Fukuoka and Haneda Airport)
  3. Add a new feature (make a list of flights that leaves before a specific time in the day/night. For example, all flights that leave before 01:00)
  4. Add a new feature (calculate the average flight time for each airline)
  5. Add a new feature (make a list of all flights sorted by arrival time)
  6. Add a new feature (calculate the total flight time for each airline)
  7. Add a new feature (make a list of all flights sorted by duration)
  8. Refactor the code where needed. Make sure that the code is clean and easy to read.