/// <summary>
        /// this func sorting list of BusLineList according to total driving times
        /// </summary>
        /// <returns>the sorted list</returns>
        public BusLineList sortedList()
        {
            BusLineList retLst = new BusLineList();

            retLst.busLst = new List <BusLine>(busLst);
            retLst.busLst.Sort();
            return(retLst);
        }
        /// <summary>
        /// this function find the buses that drive in the station
        /// </summary>
        /// <param name="station">the station that checked</param>
        /// <returns>list of buses that drive in the station</returns>
        public BusLineList findBuses(int station)
        {
            BusLineList retLst = new BusLineList();

            retLst.busLst = busLst.FindAll(bus => bus.stasionExist(station));
            if (retLst.busLst.Count == 0)
            {
                throw new ArgumentException("No buses drive in that station!");
            }
            return(retLst);
        }
Beispiel #3
0
        /// <summary>
        /// this function prints all buse lines if enter 1,
        /// or prints all buse lines numbers in all stations if enter 2.
        /// </summary>
        static void Printinfo()
        {
            int                    choice;
            BusLineList            lines    = new BusLineList();            //all the lines in current stations
            List <BusLineStations> stations = new List <BusLineStations>(); //all the stations

            Console.WriteLine("Enter 1 to print all bus lines.\n" +
                              "Enter 2 to search all buses in all stations.");
            int.TryParse(Console.ReadLine(), out choice);
            switch (choice)
            {
            //prints all bus lines
            case 1:
                foreach (BusLine cur in busLst)
                {
                    Console.WriteLine(cur);
                }
                break;

            //prints all buse lines numbers in all stations.
            case 2:
                //adding all stations to the list once
                foreach (BusLine cur in busLst)
                {
                    foreach (BusLineStations curr in cur.Stations)
                    {
                        if (!stations.Exists(station => station.BusStationKey == curr.BusStationKey))
                        {
                            stations.Add(curr);
                        }
                    }
                }
                //printing all bus line numbers
                foreach (BusLineStations cur in stations)
                {
                    lines = busLst.findBuses(cur.BusStationKey);
                    Console.WriteLine("In bus station {0} driving the bus lines:", cur.BusStationKey);
                    foreach (BusLine curr in lines)
                    {
                        Console.WriteLine(curr.BusNum);
                    }
                }
                break;

            default:
                throw new ArgumentException("Illegal input!");
            }
        }
        /// <summary>
        /// this function find the buses that drive in two stations
        /// </summary>
        /// <param name="first">the src station</param>
        /// <param name="second">the dst station</param>
        /// <returns>list of the buses that drive in two stations</returns>
        public BusLineList findBusesInTwoStations(int first, int second)
        {
            BusLineList retLst = new BusLineList();

            foreach (BusLine cur in busLst)
            {
                if (cur.subRoute(first, second) != null)
                {
                    retLst.busLst.Add(cur.subRoute(first, second));
                }
            }
            if (retLst.busLst.Count == 0)
            {
                throw new ArgumentException("No buses drive in that stations!");
            }
            return(retLst);
        }