import java.io.*; import java.util.*; 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(); addTo(friends, name1, name2); addTo(friends, name2, name1); } } return friends; } public static void addTo(Map> friends, String name1, String name2) { if (!friends.containsKey(name1)) { Set theFriends = new TreeSet<>(); friends.put(name1, theFriends); theFriends.add(name2); } else { Set theFriends = friends.get(name1); theFriends.add(name2); } } }