Practice Problem

 

Description

 

One way to get the list of directors from my Movie database  is to use the method

 

public String getAllDirectors() {

        String s = "";

        for (Movie m : movieList) {        

                s = s + m.getDirector() + "\n";    

        }

        return s;

}

 

However, the problem is that if a director is in the database for more than one movie, the director will be listed twice.

 

One solution is to add (or modify) the above method so that it returns an ArrayList instead of a single String.  Each item in the ArrayList will contain the name of a single director.  You can then make use of the contains method in the ArrayList class to check for duplicates as you loop.

 

For the example above, the new header for the above method would be

 

public ArrayList<String> getAllDirectors()

 

 

Your Task:

 

Pick a similar method in your database.  Modify or overload it so that it returns an ArrayList without duplicates.