// Prompts the user for two names and prints how distant of friends they are. // This version fixes a couple of bugs. import java.util.*; import java.io.*; public class Friends { public static void main(String[] args) throws FileNotFoundException { ?? friend = readFile("friends.dot"); System.out.println(friends); } public static ?? readFile(String filename) throws FileNotFoundException { Scanner input = new Scanner(new File(filename)); Map> friends = new TreeMap>(); while (input.hasNextLine()) { String line = input.nextLine(); if (line.contains("--")) { Scanner lineData = new Scanner(line); String name1 = lineData.next(); lineData.next(); // skip "--" String name2 = lineData.next(); if (!friends.containsKey(name1)) { Set theFriends = new TreeSet(); theFriends.add(name2); friends.put(name1, theFriends); } else { Set theFriends = friends.get(name1); theFriends.add(name2); // friends.put(name1, theFriends); } // TODO: Record friendship between name1 and name2 } } return friends; } }