Beispiel #1
0
        /// <summary>
        /// FindTrain method which takes trainID, then return Train object
        /// </summary>
        /// <param name="trainID">TrainID of the train to be searched</param>
        /// <returns>Train object</returns>
        public Train FindTrain(int trainID)
        {
            Train searchTrain = new Train();

            foreach (object item in RailwayData.trains.Keys)
            {
                if (Convert.ToInt32(item) == trainID)
                {
                    searchTrain = (Train)RailwayData.trains[item];
                    break;
                }
            }
            if (searchTrain.TrainID == 0)
            {
                TrainNotFoundException notFound = new TrainNotFoundException("The train you are searching is not found");
                throw notFound;
            }
            return(searchTrain);
        }
Beispiel #2
0
        /* overloading of methods - static polymorphism*/
        /// <summary>
        /// FindTrain method which takes fromlocation,tolocation and date , then return Train object
        /// </summary>
        /// <param name="fromLocation">From station paramater</param>
        /// <param name="toLocation">Tostaion parameter</param>
        /// <param name="day">day parameter on which day train to be search </param>
        /// <returns>Train object</returns>
        public Train FindTrain(string fromLocation, string toLocation, DateTime day)
        {
            Train searchTrain = new Train();

            foreach (object schedule in RailwayData.trainSchedule.Keys)
            {
                TrainSchedule trainSchedule = (TrainSchedule)RailwayData.trainSchedule[schedule];
                if (trainSchedule.FromStation == fromLocation && trainSchedule.ToStation == toLocation && trainSchedule.WeekDay == day.DayOfWeek.ToString())
                {
                    searchTrain = (Train)RailwayData.trains[schedule];
                    break;
                }
            }
            if (searchTrain.TrainID == 0)
            {
                TrainNotFoundException notFound = new TrainNotFoundException("The train you are searching is not found");
                throw notFound;
            }
            return(searchTrain);
        }