⌛⌛ Movie data vs stream¶
Place your code into files named Movie.java and MovieAnalytics.java in the directory
Round8/streams. Also remember to pull task material from
This task concerns basic use of Java streams. The goal is to implement a class
that offers functions for reading movie data from a file and then processing the data with Java
streams. You also need to implement a simple class
Movie for representing movie data.
Implement these two classes as follows:
Movieshould have the following public features:
Movie(String title, int releaseYear, int duration, String genre, double score, String director)that initializes the object to holds the information provided by the constructor parameters: movie title, release year, duration, genre, rating score and director.
Getter functions for all these: e.g.
getReleaseYear(), and so on.
MovieAnalyticsshould have the following public features:
MovieAnalytics()that initializes an empty movie database. E.g. a simple
Movielist will suffice for this task.
Static member function
Consumer<Movie> showInfo()that returns an object that implements the interface
Consumer<Movie>and whose function
accept(Movie t)prints out information of the movie
tin the form “
title (By director, releaseYear)\\n” (see the example output files for details).
void populateWithData(String fileName)that reads movie data from the file spedicifed by the parameter.
The file is expected to contain lines of form “
title;releaseYear;duration;genre;score;director”. That is, each line describes one movie and includes the same set of information that the constructor of
Movietakes as parameters.
A straight-forward split operation using a semicolon as a separator will work fine. Then you just need to convert some parts into suitable numbers.
Stream<Movie> moviesAfter(int year)that returns a stream that lists all movies released in the year
Stream<Movie> moviesBefore(int year)that returns a stream that lists all movies released in the year
Stream<Movie> moviesBetween(int yearA, int yearB)that returns a stream that lists all movies released between the years
Stream<Movie> moviesByDirector(String director)``that returns a stream that lists all movies directed by ``director.
The last four functions must return a stream that lists the movies in ascending order of release
year. Movies with the same release year are orderd by title (using the natural
A note about returning a stream: return a stream that has been set to perform intermediate (but no
terminal) operations. E.g a stream that lists the unique items of the array
int ia = [1, 2, 5, 4, 2, 5, 4] in sorted order could be created and returned as
return Arrays.stream(ia).distinct().sorted();. The recipient of this stream could then read the
values 1, 2, 4 and 5 from the stream.
You may test your implementation by using the test program given in the file
the example output given in the files
these files to the same directory with your code, compile the test program e.g. as
javac *.java, and run the tests as
java MovieTest input1.txt,
java MovieTest input2.txt
java MovieTest input3.txt. The expected outputs of these tests are given in the files
A+ presents the exercise submission form here.