/// <summary> /// Lines passing through the station according to the station number. /// </summary> /// <param name="collectionOfbusLines"></param> public static void SearchBus(ref CollectionOfBusLines collectionOfbusLines) { int Ssrarch; Console.WriteLine("Enter a statian number to search: "); while (!int.TryParse(Console.ReadLine(), out Ssrarch)) { Console.WriteLine("rong number!!! enter again: "); } List <int> temp = collectionOfbusLines.StationLines(Ssrarch); Console.WriteLine("The lines that pass through this station are: "); foreach (int item in temp) { Console.WriteLine(); Console.WriteLine(item); } Console.WriteLine("Very Good"); }
/// <summary> /// /// </summary> /// <param name="args"></param> static void Main(string[] args) { CollectionOfBusLines collectionOfbusLines = new CollectionOfBusLines(); List <BusLineStation> buslinestation = new List <BusLineStation>(); // Initial initialization of ten lines according to the requirements within the loop has a call to function. int numberOfStatian; int numberLine; for (int i = 0; i < 10; i++) { numberLine = r.Next(999); numberOfStatian = r.Next(2, 10); BusLine busLine = new BusLine(numberLine); collectionOfbusLines.CollectionOfLines = AddLineFirstly(ref busLine, ref buslinestation, numberOfStatian); Console.WriteLine("good the Line insrted to list "); } //Two lines that will pass at all stations as required in the exercise. for (int i = 0; i < 2; i++) { numberLine = r.Next(999); BusLine busLine1 = new BusLine(numberLine) { RouteTheLine = buslinestation }; collectionOfbusLines.CollectionOfLines = busLine1; } int number; Console.WriteLine(@" Enter 1 to add a new bus line and station to line: Enter 2 to delete a bus line and to delete a station: Enter 3 to find the lines that pass through the station: Enter 4 to Print the data: Enter -1 to Exit :"); Console.WriteLine(); Console.WriteLine("Enter a number to choose from the enum"); while (!int.TryParse(Console.ReadLine(), out number)) { Console.WriteLine("rong number!!! enter again:"); } myenum choice = (myenum)number; while (choice != myenum.Exit) { switch (choice) { case myenum.AddNewBus: try { AddNewBus1(ref collectionOfbusLines); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } break; case myenum.AddStatian: try { AddStatian1(ref collectionOfbusLines); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } break; case myenum.DeleteBus: try { DeleteLine(ref collectionOfbusLines); } catch (FormatException ex) { Console.WriteLine(ex.Message); } break; case myenum.DeleteStatian: try { DeleteStation(ref collectionOfbusLines); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } break; case myenum.SearchLinesAtTheStation: try { SearchBus(ref collectionOfbusLines); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } break; case myenum.SearchTimeTravelOptions: try { SearchTime(ref collectionOfbusLines); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } break; case myenum.PrintOllBuses: foreach (BusLine item1 in collectionOfbusLines) { Console.WriteLine(item1); } break; case myenum.PrintBusesAndStations: List <int> temp = new List <int>(); foreach (BusLine item2 in collectionOfbusLines) { foreach (BusLineStation item3 in item2.RouteTheLine) { temp.Add(item3.StationNumber); } } for (int i = 0; i < temp.Count; i++) { List <int> temp1 = collectionOfbusLines.StationLines(temp[i]); Console.WriteLine("At station number: " + temp[i] + " The lines pass is: "); for (int j = 0; j < temp1.Count; j++) { Console.WriteLine(temp1[j]); } temp1.Clear(); } break; case myenum.Exit: break; default: Console.WriteLine("end of progrem: "); break; } Console.WriteLine(); Console.WriteLine("enter a number: "); while (!int.TryParse(Console.ReadLine(), out number)) { Console.WriteLine("rong number!!! enter again: "); } choice = (myenum)number; Console.WriteLine(); } _ = Console.ReadKey(); }