Document databases: Practical Exercise

We assume you have already completed the tutorial on a separate page.

Please write a Java program using the DoctorWho API to solve the following exercise.

In Moodle, please submit your solution as a file called Exercise3.java. We recommend developing and debugging on your own machine before going to Moodle.

Exercise 3 (Tick 3)

Recall relational exercise 1c, in which you searched for pairs of actors who share the top billing of a movie. Let's implement the same thing using the document database.

As usual, the program should take the path to the database directory as the first command-line argument. The second command-line argument should be a number, namely the position to search for. If that number is x, we search for two actors who both have position x on the same movie.

Fill in the following template:

import uk.ac.cam.cl.databases.moviedb.MovieDB;
import uk.ac.cam.cl.databases.moviedb.model.*;

public class Exercise3 {
    public static void main(String[] args) {
        try (MovieDB database = MovieDB.open(args[0])) {
            int requiredPosition = Integer.parseInt(args[1]);
            // YOUR CODE GOES HERE
        }
    }
}

You should be able to compile and run it as usual:

# On Windows
javac -classpath document-db.jar Exercise3.java
java -classpath .;document-db.jar Exercise3 document-small 1

# On Linux or Mac OS
javac -classpath document-db.jar Exercise3.java
java -classpath .:document-db.jar Exercise3 document-small 1

With the number 1 as position argument (as in the command line above) it should produce the following output:

Owen, Clive (I) and Yacuzzi, Juan Gabriel both have position 1 in Children of Men (2006)

If you change number 1 to 4, it should produce the following output:

Chevalier, Jon and Moore, Julianne both have position 4 in Children of Men (2006)
Batey, Toya and Williams, Cobe both have position 4 in The Interrupters (2011)

The actor names should appear in alphabetical order.