The file films.txt, available on BlackBoard, contains information describing a number of
films, including the title, the year in which it was released, the certificate (e.g. “R” or “PG13”, indicative of the content and the audience for which the film is considered suitable), the
genres describing the film, its duration in minutes, and the average rating awarded by viewers.
The program must load the information in this file into a suitable collection of objects, so that
database queries could be answered. The program should consist of at least the following three
java source files:
- Film.java - A Film object describes the information about a particular film. The class
should provide a suitable collection of constructors, accessor methods, toString etc.
The class should also implement the Comparable interface, to simplify the sorting of a
collection of Film objects into chronological order.
- FilmDatabase.java - A collection of Film objects, one for each movie in the file. The
class should provide methods for reading the data in from a file and for answering generic
database queries. Rather than writing a program that only implements the current specifications, we should write maintainable programs that are easily extended to answer a
variety of database queries without writing a lot of extra code.
- Main.java - This class contains the main method, and uses the services provided by
Film and FilmDatabase to answer the required database queries.
Deciding the appropriate set of methods required for each class is an important element of the
The program must have a main function, in a source file called Main.java, that performs
the following operations:
- Read in a database from the file films.txt, provided via BlackBoard.
- Display the entire collection of films, arranged in ascending order of duration (shortest
film first). The movies must be displayed in the same format in which they appear in the
- Display the highest rated horror film.
- Display the fifteenth longest “R” rated film.
- Display the film with the shortest name.
- Display the number of years separating the oldest film and the newest.
• Tackle the problem one module at a time (I would start with Film.java; have it more or
less fully implemented and tested before moving on to FilmDatabase.java and then
build the program Main.java from the components already constructed). Note this is
an example of “top-down design, bottom-up implementation” discussed in the lectures.
• For each module, it is a good idea to work out what interface functions the class should
provide in order to provide the services needed to implement the program, before starting to code. If implementing the classes proves unduly difficult, this is often because the
design of the classes is the problem.
• Make sure you have a good idea of what you have to do before you start writing code,
and separate the task of working out what you want the computer to do from the task
of working out how to tell it to do it.
• It is important to test each module in isolation (don’t write all the code for all four modules and expect them to work first time). Each module should have a test harness.
• Implementation of FilmDatabase.java requires the use of an array or ArrayList.
However Film.java can be implemented and tested, based on the material already covered, so that is probably the best place to start.
• When loading the data from a file, it is easier if the Film class is equipped with a constructor that initialises a Film object using a String containing a line from the file film.txt,
i.e. so that we could create a Film using the following code fragment:
String s = “” Rashomon " ,1950 ," UNRATED " ," Crime / Drama / Mystery " ,88 ,0";
Film film = new Film ( s );