public class A1Q1 { public static void main(String[] args) { int numActors = JMDBSource.getNumActors(); int numMovies = JMDBSource.getNumMovies(); String[] firstNames = new String[numActors]; String[] lastNames = new String[numActors]; int[] birthYears = new int[numActors]; JMDBSource.fillActorArrays(lastNames, firstNames, birthYears); //*** fill parallel arrays with actor information. String[] movieTitles = new String[numMovies]; String[] starFirst = new String[numMovies]; String[] starLast = new String[numMovies]; int[] years = new int[numMovies]; JMDBSource.fillMovieArrays(movieTitles, years, starFirst, starLast); //starfirst and last might be null //*** fill parallel arrays with movie information. Actor[] actorArray = new Actor[numActors]; Movie[] movieArray = new Movie[numMovies]; for (int i=0; i < numActors; i++) { actorArray[i] = new Actor(firstNames[i], lastNames[i], birthYears[i]); //*** fill the actor array up } for (int i=0; i < numMovies; i++) { if (starFirst[i] == null) { movieArray[i] = new Movie(movieTitles[i], years[i]); } else { for (int j=0; j < numActors; j++) { if (firstNames[j].equals(starFirst[i]) && lastNames[j].equals(starLast[i]) ) { movieArray[i] = new Movie(movieTitles[i], years[i], actorArray[j]); } } } } printMovies(movieArray); System.out.println("\n---End of processing."); } public static void printMovies(Movie[] movies) { System.out.println("Movies and their stars:"); for (int i=0; i < movies.length; i++) { movies[i].printMovie(); } } } class Actor { private String lastName, firstName; private int birthYear; public Actor(String first, String last, int year) { this.firstName = first; this.lastName = last; this.birthYear = year; } public String getName() { return (firstName + " " + lastName); } public int getBirthYear() { return birthYear; } } class Movie { private String title; private int year; private Actor star = null; public Movie(String title, int year) { this.title = title; this.year = year; } public Movie(String title, int year, Actor star) { this.title = title; this.year = year; this.star = star; } public void printMovie() { System.out.println(title + " (" + year + ")"); if (star != null) { System.out.println(" Starring:" + star.getName() + " (" + year + ") ( Age: " + (year - star.getBirthYear()) + ")\n"); } else { System.out.println(" (No Stars)\n"); } } }