import java.util.*; // Class to help test question 5. // Write your solution to twoFlightsAway in this class. // It will not compile until you add your method! public class TestQ5 { public static void main(String args[]) { // Build up map from example Map> flights = new HashMap>(); addFlights(flights, "Cairo", "Ottawa", "Rome"); addFlights(flights, "Ottawa", "Cairo", "Seattle", "Tokyo"); addFlights(flights, "Pyrus"); addFlights(flights, "Rome", "Cairo"); addFlights(flights, "Seattle", "Ottawa", "Tokyo"); addFlights(flights, "Tokyo", "Ottawa", "Seattle"); Map> twoAway = twoFlightsAway(flights); System.out.println(twoAway); checkEquals("Example from spec", twoFlightsAway(flights).toString(), "{Cairo=[Seattle, Tokyo], Ottawa=[Rome], Rome=[Ottawa], Seattle=[Cairo], Tokyo=[Cairo]}"); } // Adds flight information from the starting point to each destination in destinations (an array) public static void addFlights(Map> flights, String start, String... destinations) { flights.put(start, new HashSet<>()); for (String dest : destinations) { flights.get(start).add(dest); } } // Checks if the expcted value matches the value received. Prints out information // (including a description) explaining what was tested and if it succeded. // Also prints a note in the case of test failure to indicate any special cases. public static void checkEquals(String description, E received, E expected) { System.out.print("Testing " + description + " ... "); if (expected.equals(received)) { System.out.println("Passed!"); } else { System.out.println("Does not match!"); System.out.println(" Received: " + received); System.out.println(" Expected: " + expected); } } }