import java.io.*; import java.util.*; // keys are names // array of strings // fixed size // Set : friends // no duplicates // non-linear (but we don't care) // Map> public class Friends1 { public static void main(String[] args) throws FileNotFoundException { System.out.println("Welcome to the cse143 friend finder."); Scanner input = new Scanner(new File("friends.dot")); Map> friends = readFile(input); System.out.println(friends); // more to do } public static Map> readFile(Scanner input) { 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(); // this skips the "--" token String name2 = lineData.next(); // process names addTo(friends, name1, name2); addTo(friends, name2, name1); } } return friends; } // getSet() public Set getSet() { return new HashSet(); } // adds name2 to the set of names given my friends.get(name1) // name1 -> [x, y, z, name2] public static void addTo(Map> friends, String name1, String name2) { if (!friends.containsKey(name1)) { friends.put(name1, new TreeSet()); } Set friendsOfName1 = friends.get(name1); friendsOfName1.add(name2); } // post: computes the distance between two people, printing the various // lists of friends with their distance from name1 public static void showMatches(Map> friends, String name1, String name2) { int distance = 0; System.out.println(); System.out.println("Starting with " + name1); } }