Exemple #1
0
        /// <summary>
        /// get a bus stop from the user
        /// </summary>
        /// <param name="myBusCollection">the Collection of all the bus </param>
        /// <param name="myUniqueStops">a list of stop</param>
        /// <returns></returns>
        public static BusStop GetBusStop(BusCollection myBusCollection, ref List <BusStop> myUniqueStops)
        {
            BusStop ret        = new BusStop();
            int     realChoice = 0;
            string  choice     = "";
            bool    keyOk      = false;

            while (!keyOk)
            {
                Console.WriteLine("enter bus station key");
                ret.m_mylocation.m_busStationKey = Program_6077_5711_01.getInt(choice, ref realChoice);
                if (myBusCollection.keyExist(realChoice))
                {
                    Console.WriteLine("ERROR bus key taken!!");
                }
                else
                {
                    keyOk = true;
                }
            }
            if (!myBusCollection.keyExist(ret.m_mylocation.m_busStationKey))
            {
                myBusCollection.m_BusKeysList.Add(ret.m_mylocation.m_busStationKey);
                myUniqueStops.Add(ret);
            }
            return(ret);
        }
Exemple #2
0
        /// <summary>
        /// get a bus route from the user
        /// </summary>
        /// <param name="myBusCollection">the Collection of all the bus</param>
        /// <param name="myUniqueStops">a list of stop</param>
        /// <returns></returns>
        public static BusRoute GetBusRoute(BusCollection myBusCollection, ref List <BusStop> myUniqueStops)
        {
            BusStop temBusStop = new BusStop();
            int     realChoice = 0;
            string  choice     = "";

            BusRoute temp = new BusRoute();

            Console.WriteLine("enter bus line:");
            realChoice = Program_6077_5711_01.getInt(choice, ref realChoice);
            while (realChoice <= 0)
            {
                Console.WriteLine("enter positive number");
                realChoice = Program_6077_5711_01.getInt(choice, ref realChoice);
            }
            temp.m_BusLine = realChoice;


            Console.WriteLine("enter firstStation:");
            temp.m_FirstStation = Console.ReadLine();


            Console.WriteLine("enter lastStation:");
            temp.m_LastStation = Console.ReadLine();

            Console.WriteLine("enter bus area:");
            temp.m_Area = Console.ReadLine();

            Console.WriteLine("enter list of bus stop:");
            realChoice = 1;

            do
            {
                Console.WriteLine("enter 1 to add more bus stop enter 2 to end");
                realChoice = Program_6077_5711_01.getInt(choice, ref realChoice);
                if (realChoice != 2)
                {
                    temBusStop = GetBusStop(myBusCollection, ref myUniqueStops);
                    temp.add(temBusStop, temp.m_Stations.Count);
                }
            } while (realChoice != 2);
            return(temp);
        }
Exemple #3
0
        /// <summary>
        /// find a specific stop and delete it
        /// </summary>
        /// <param name="myBusCollection">the Collection of all the bus</param>
        /// <param name="myUniqueStops">a list of stop</param>
        public static void FindAndDelete(BusCollection myBusCollection, ref List <BusStop> myUniqueStops)
        {
            int    place = 0;
            string firstStation, lastStation;
            int    tempBusLine;
            int    realChoice = 0;
            string choice     = "";

            Console.WriteLine("enter bus line:");
            realChoice = Program_6077_5711_01.getInt(choice, ref realChoice);
            while (realChoice <= 0)
            {
                Console.WriteLine("enter positive number");
                realChoice = Program_6077_5711_01.getInt(choice, ref realChoice);
            }
            tempBusLine = realChoice;


            Console.WriteLine("enter firstStation:");

            firstStation = Console.ReadLine();


            Console.WriteLine("enter lastStation:");

            lastStation = Console.ReadLine();

            foreach (BusRoute myBusRoute in myBusCollection)
            {
                if ((myBusRoute.m_BusLine == tempBusLine) && (myBusRoute.m_LastStation == lastStation) && (myBusRoute.m_FirstStation == firstStation))
                {
                    Console.WriteLine("what is the bus station key of this stop?");
                    realChoice = Program_6077_5711_01.getInt(choice, ref realChoice);
                    while (realChoice <= 0)
                    {
                        Console.WriteLine("enter positive number");
                        realChoice = Program_6077_5711_01.getInt(choice, ref realChoice);
                    }
                    foreach (BusStop stop in myBusRoute.m_Stations)
                    {
                        if (stop.m_mylocation.m_busStationKey == realChoice)
                        {
                            try
                            {
                                myBusRoute.delete(place);
                            }
                            catch (ArgumentOutOfRangeException ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                            break;
                        }
                        place++;
                    }
                }
            }
            foreach (BusStop stop in myUniqueStops)
            {
                if (stop.m_mylocation.m_busStationKey == realChoice)
                {
                    myUniqueStops.Remove(stop);
                    break;
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// User menu
        /// </summary>
        /// <param name="myBusCollection">the Collection of all the bus</param>
        public static void LineManagement(ref BusCollection myBusCollection)
        {
            List <BusStop> myUniqueStops = new List <BusStop>();

            initializeBusRoute(ref myBusCollection, ref myUniqueStops);
            bool          NotEnd = true;
            int           countBus = 0;
            BusStop       firstStop = new BusStop(), lastStop = new BusStop(), addeDStop = new BusStop();
            BusCollection pathCollection = new BusCollection();

            while (NotEnd)
            {
                Console.WriteLine("OPTIONS:\n1: ADD\n2: DELETE\n3: SEARCH\n4: PRINT \n5: EXIT");
                string choice = "";
                int    realChoice = 0, placeAdd = 0;
                realChoice = Program_6077_5711_01.getInt(choice, ref realChoice);
                switch (realChoice)
                {
                case (int)menuChoice.ADD:
                    Console.WriteLine("1: add bus Stop\n2: add busLine");
                    realChoice = Program_6077_5711_01.getInt(choice, ref realChoice);
                    switch (realChoice)
                    {
                    case (int)menuAdd.ADD_BUS_STOP:
                        do
                        {
                            Console.WriteLine("enter busLine range 0 - {0}:\n", myBusCollection.m_BusCollectionList.Count);
                            placeAdd = Program_6077_5711_01.getInt(choice, ref realChoice);
                            if (placeAdd > myBusCollection.m_BusCollectionList.Count || placeAdd < 0)
                            {
                                Console.WriteLine("ERROR");
                            }
                        } while (placeAdd > myBusCollection.m_BusCollectionList.Count || placeAdd < 0);
                        addeDStop = GetBusStop(myBusCollection, ref myUniqueStops);
                        try
                        {
                            myBusCollection[placeAdd].add(addeDStop, myBusCollection[placeAdd].m_Stations.Count);
                        }
                        catch (IndexOutOfRangeException ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        break;

                    case (int)menuAdd.ADD_BUS_ROUTE:
                    {
                        myBusCollection.addBusRoute(GetBusRoute(myBusCollection, ref myUniqueStops));
                    }
                    break;

                    default:
                        Console.WriteLine("wrong choice!!!");
                        break;
                    }
                    break;

                case (int)menuChoice.ERASE:
                    BusRoute temp = new BusRoute();
                    Console.WriteLine("enter 1 to erase bus route  2 - to erase stope");
                    realChoice = Program_6077_5711_01.getInt(choice, ref realChoice);
                    switch (realChoice)
                    {
                    case (int)menuDelete.DELETE_BUS_ROUTE:
                        Console.WriteLine("enter bus line key to be deleted:");
                        realChoice = Program_6077_5711_01.getInt(choice, ref realChoice);
                        try
                        {
                            myBusCollection.deleteBusRouteKey(realChoice);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);;
                        }
                        break;

                    case (int)menuDelete.DELETE_STOP:
                        Console.WriteLine("enter the line number details at the station for deletion");
                        FindAndDelete(myBusCollection, ref myUniqueStops);
                        break;

                    default:
                        Console.WriteLine("wrong choice!!!");
                        break;
                    }
                    break;

                case (int)menuChoice.SEARCH:
                    Console.WriteLine("1: print all busses that pass in a bus stop\n2:find all paths");
                    realChoice = Program_6077_5711_01.getInt(choice, ref realChoice);
                    switch (realChoice)
                    {
                    case (int)menuSearch.LINES_THAT_PASS_IN_STOP:
                        Console.WriteLine("enter bus stop key:");
                        realChoice = Program_6077_5711_01.getInt(choice, ref realChoice);
                        foreach (BusRoute bus in myBusCollection.BusStopList(realChoice))
                        {
                            try
                            {
                                bus.print();
                            }
                            catch (ArgumentNullException ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                        }
                        break;

                    case (int)menuSearch.FIND_PATH:
                        do
                        {
                            try
                            {
                                Console.WriteLine("enter first station key");
                                realChoice = Program_6077_5711_01.getInt(choice, ref realChoice);
                                firstStop  = myBusCollection.retStop(realChoice);
                                NotEnd     = true;
                            }
                            catch (NotFoundkey exception)
                            {
                                Console.WriteLine(exception.Message);
                                NotEnd = false;
                            }
                        } while (!NotEnd);
                        do
                        {
                            try
                            {
                                Console.WriteLine("enter last station key");
                                realChoice = Program_6077_5711_01.getInt(choice, ref realChoice);
                                lastStop   = myBusCollection.retStop(realChoice);
                            }
                            catch (NotFoundkey exception)
                            {
                                Console.WriteLine(exception.Message);
                                NotEnd = false;
                            }
                        } while (!NotEnd);
                        if (!(lastStop.m_distance == 0 || firstStop.m_distance == 0))
                        {
                            foreach (BusRoute bus in myBusCollection)
                            {
                                pathCollection.addBusRoute(bus.Section(firstStop, lastStop));
                            }
                            foreach (BusRoute bus in pathCollection)
                            {
                                try
                                {
                                    bus.print();
                                }
                                catch (ArgumentNullException ex)
                                {
                                    Console.WriteLine(ex.Message);
                                }
                                Console.WriteLine(bus.travelTime(bus.m_Stations[0], bus.m_Stations[bus.m_Stations.Count - 1]));
                            }
                        }
                        else
                        {
                            Console.WriteLine("ERROR NO SUCH STOP");
                        }
                        break;

                    default:
                        Console.WriteLine("wrong choice!!!");
                        break;
                    }
                    break;

                case (int)menuChoice.PRINT:

                    try
                    {
                        Console.WriteLine("1: print all busses\n2:print all stops");
                        realChoice = Program_6077_5711_01.getInt(choice, ref realChoice);
                        switch (realChoice)
                        {
                        case (int)menuPrintInfo.printAllBusses:
                            foreach (BusRoute bus in myBusCollection)
                            {
                                Console.WriteLine(bus);
                            }
                            break;

                        case (int)menuPrintInfo.printBusStopInfo:
                            int countBus2 = 0;
                            foreach (BusStop stop in myUniqueStops)
                            {
                                Console.WriteLine(stop);
                                countBus2 = 0;
                                foreach (BusRoute route in myBusCollection.BusStopList(stop.m_mylocation.m_busStationKey))
                                {
                                    Console.WriteLine(route);
                                    countBus2++;
                                }
                                Console.WriteLine("");
                            }
                            break;
                        //case (int)menuPrintInfo.printAllInfo:
                        //    countBus = 0;

                        //    foreach (BusRoute bus in myBusCollection)
                        //    {
                        //        Console.WriteLine("bus number {0}", countBus);
                        //        try
                        //        {
                        //            bus.print();
                        //        }
                        //        catch (NullReferenceException ex)
                        //        {
                        //            Console.WriteLine(ex.Message);
                        //        }
                        //        Console.WriteLine("");
                        //        Console.WriteLine("###  BUS LIST: ###");
                        //        try
                        //        {
                        //            bus.printStops();
                        //        }
                        //        catch (NullReferenceException ex)
                        //        {
                        //            Console.WriteLine(ex.Message);
                        //        }
                        //        countBus++;
                        //    }
                        //    break;
                        default:
                            Console.WriteLine("wrong choice!!!");
                            break;
                        }
                    }
                    catch (ArgumentNullException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    break;

                case (int)menuChoice.EXIT:
                    Console.WriteLine("bye bye!!!");
                    NotEnd = false;
                    break;

                default:
                    Console.WriteLine("wrong choice please try again!");
                    break;
                }
            }
        }