import java.util.*; import java.io.*; public class KevinBacon { public static void main(String[] args) throws FileNotFoundException { ISearchableGraph graph = buildGraph(); System.out.println(graph); } public static ISearchableGraph buildGraph() throws FileNotFoundException { Scanner input = new Scanner(new File("movies.txt")); ISearchableGraph graph = new SearchableGraph(); while (input.hasNextLine()) { Scanner line = new Scanner(input.nextLine()).useDelimiter(";"); String movie = line.next(); // get all of the actors in the movie List actors = new ArrayList(); while (line.hasNext()) { String actor = line.next(); graph.addVertex(actor); actors.add(actor); } // connect all of the actors for (int i = 0; i < actors.size(); i++) { for (int j = 1; j < actors.size(); j++) { graph.addEdge(actors.get(i), actors.get(j), movie); } } } return graph; } }