1.4-Software-Development-Principles

JSON and streams

You are going to practice using Java streams by executing the exercises below.

Setup

Download the project zip file. Inspect the code.

Have a look at the Streams class. This is where you must implement your stream functions. You can make use of the following data structures (Lists)

The objects in the list are automatically created from the db.json file. You do not have to understand how this is done before making the exercises.

Exercise 1 Filter

Use the query() function to write your stream code. You can simply use a System.out.println to check your results.

Create a list of the names of the movies which are longer than 120 minutes and the title contains more than two words

Exercise 2 Min

Show the the minimal duration of all movies

Exercise 3 Limit

Show the two longest movies

Exercise 4 Filter and map

Show all movie durations in hours (type = double) which are longer than 120 minutes

Exercise 5 Reduce

Show the sum of all movie durations

Exercise 6 Collect to map

Get a map of all movie titels as key, and durations as value

Exercise 7 Nested calls

Show all the rentals of the movies longer than 120 minutes

Exercise 8 flatMap

Make a list of unique movies which were rented after 30 nov 2020