public static void Main2(string[] args) { if (args.Length != 2) { Console.WriteLine("Usage: SubwayTester [startStation] [endStation]"); Environment.Exit(-1); } try { SubwayLoader loader = new SubwayLoader(); Subway objectville = loader.LoadFromFile("ObjectvilleSubway.txt"); if (!objectville.HasStation(args[0])) { Console.WriteLine(args[0] + " is not a station in Objectville."); Environment.Exit(-1); } else if (!objectville.HasStation(args[1])) { Console.WriteLine(args[1] + " is not a station in Objectville."); Environment.Exit(-1); } List <Connection> route = objectville.GetDirections(args[0], args[1]); SubwayPrinter printer = new SubwayPrinter(); printer.PrintDirections(route); } catch (KeyNotFoundException e) { Console.WriteLine(e); } }
private void LoadStations(Subway subway, StreamReader reader) { string currentLine; currentLine = reader.ReadLine(); while (currentLine.Length > 0) { subway.AddStation(currentLine); currentLine = reader.ReadLine(); } }
private void LoadLine(Subway subway, StreamReader reader, string lineName) { string station1Name, station2Name; station1Name = reader.ReadLine(); station2Name = reader.ReadLine(); while ((station2Name != null) && (station2Name.Length > 0)) { subway.AddConnection(station1Name, station2Name, lineName); station1Name = station2Name; station2Name = reader.ReadLine(); } }
public static void Main(string[] args) { try { SubwayLoader loader = new SubwayLoader(); Subway objectville = loader.LoadFromFile("ObjectvilleSubway.txt"); Console.WriteLine("Testing stations..."); if (objectville.HasStation("Head First Lounge") && objectville.HasStation("Objectville Diner") && objectville.HasStation("Objectville Diner")) { Console.WriteLine("... station test PASSED successfully."); } else { Console.WriteLine("... station test FAILED."); Environment.Exit(-1); } Console.WriteLine("\nTesting connections..."); if (objectville.HasConnection("HeadFirstLabs", "LSP Lane", "Booch Line") && objectville.HasConnection("SRP Square", "OCP Orchard", "Liskov Line") && objectville.HasConnection("OOA&D Oval", "Head First Lounge", "Gamma Line")) { Console.WriteLine("... conncetions test PASSED succesfully."); } else { Console.WriteLine("... connections test FAILED."); Environment.Exit(-1); } } catch (Exception e) { Console.WriteLine(e.Message); } }
public SubwayLoader() { this.subway = new Subway(); }