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.
The following SQL counts the number of actors with Bacon distance of 1 starting from Lawrence, Jennifer (III), with person_id = 3382035.
select count(distinct c2.person_id) as total
from credits AS c1
join credits AS c2 on c2.movie_id = c1.movie_id
where c1.type = 'actor' and c2.type = 'actor'
and c1.person_id = 3382035 and c2.person_id <> 3382035;
Your task is to fill in the following java template to compute the same result as this SQL.
import java.util.*;
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) {
// The set of person_id's that we want to count
// If you want to add id (of type int) to the set
// simply use pid_set.add(id)
Set<Integer> pid_set = new HashSet<Integer>();
// open database
try (MovieDB database = MovieDB.open(args[0])) {
//
// YOUR CODE GOES HERE
//
System.out.println(pid_set.size());
}
}
}
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-movie-db # On Linux or Mac OS javac -classpath document-db.jar Exercise3.java java -classpath .:document-db.jar Exercise3 document-movie-db