Example #1
0
        /// <summary>
        /// Adding a new line
        /// </summary>
        /// <param name="collectionOfbusLines"></param>
        public static void AddNewBus1(ref CollectionOfBusLines collectionOfbusLines)
        {
            int    numberline, NumberOfStation, NumStation;
            string Address;

            Console.WriteLine("Enter a line number: ");
            while (!int.TryParse(Console.ReadLine(), out numberline))
            {
                Console.WriteLine("rong number!!! enter again:");
            }
            Console.WriteLine("Enter the number of stations in the line: ");
            while (!int.TryParse(Console.ReadLine(), out NumberOfStation))
            {
                Console.WriteLine("rong number!!! enter again: ");
            }
            if (NumberOfStation < 2)
            {
                throw new ArgumentException("Error!!! The line must have a minimum of two stations");
            }
            else
            {
                BusLine busLineadd = new BusLine(numberline);
                for (int i = 0; i < NumberOfStation; i++)
                {
                    Console.WriteLine("Enter number of statian: ");
                    while (!int.TryParse(Console.ReadLine(), out NumStation))
                    {
                        Console.WriteLine("rong number!!! enter again: ");
                    }
                    try
                    {
                        if (!PlaceStations(NumStation, busLineadd, collectionOfbusLines))
                        {
                            Console.WriteLine("enter Address of the statian");
                            Address = Console.ReadLine();
                            busLineadd.AddLineToTheRoundTrip(i, new BusLineStation(NumStation, Address));
                        }
                        else
                        {
                            --i;
                            throw new ArgumentException("Error!!! The station was in a different location");
                        }
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                collectionOfbusLines.CollectionOfLines = busLineadd;
                Console.WriteLine("Very Good");
            }
        }
Example #2
0
        /// <summary>
        /// Printing options sorted from short to long travel times between two stations.
        /// </summary>
        /// <param name="collectionOfbusLines"></param>
        public static void SearchTime(ref CollectionOfBusLines collectionOfbusLines)
        {
            int StartingStation, DestinationStation;

            Console.WriteLine();
            Console.WriteLine("Please enter a departure station: ");
            while (!int.TryParse(Console.ReadLine(), out StartingStation))
            {
                Console.WriteLine("rong number!!! enter again: ");
            }

            Console.WriteLine("Please enter a departure station: ");
            while (!int.TryParse(Console.ReadLine(), out DestinationStation))
            {
                Console.WriteLine("rong number!!! enter again: ");
            }

            List <BusLine> busLines = new List <BusLine>();
            bool           flag     = false;

            foreach (BusLine item in collectionOfbusLines)
            {
                if (item.InRoute(StartingStation) && item.InRoute(DestinationStation))
                {
                    flag = true;
                    BusLine bus = item.SubRouteOfTheLine(StartingStation, DestinationStation);
                    bus.LineNumber = item.LineNumber;
                    bus.Area1      = item.Area1;
                    busLines.Add(bus);
                }
            }

            if (!flag)
            {
                throw new ArgumentException("Error!!! The two stations were not found in any line");
            }

            collectionOfbusLines.CollectionOfLines1 = busLines;
            _ = collectionOfbusLines.SortTravelTimesOnLines();
            foreach (BusLine item in collectionOfbusLines)
            {
                Console.WriteLine("Line number:  {0}", item);
            }
        }
Example #3
0
        /// <summary>
        /// An auxiliary function that checks that no two station numbers are the same in different areas.
        /// </summary>
        /// <param name="numberOfStation"></param>
        /// <param name="busLineadd"></param>
        /// <param name="collectionOfbusLines"></param>
        /// <returns></returns>
        public static bool PlaceStations(int numberOfStation, BusLine busLineadd, CollectionOfBusLines collectionOfbusLines)
        {
            bool flag = false;

            foreach (BusLine item in collectionOfbusLines)
            {
                if (item.Area1 != busLineadd.Area1)
                {
                    foreach (BusLineStation item1 in item.RouteTheLine)
                    {
                        if (item1.StationNumber == numberOfStation)
                        {
                            flag = true;
                        }
                    }
                }
            }
            return(flag);
        }
Example #4
0
        /// <summary>
        /// A function that receives an object of the bus line type, a list of objects of line stations, and the number of stations in the line.
        /// and makes an initial boot to ten lines and includes the requirements.
        /// </summary>
        /// <param name="busLine"></param>
        /// <param name="buslinestation"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public static BusLine AddLineFirstly(ref BusLine busLine, ref List <BusLineStation> buslinestation, int count)
        {
            List <BusLineStation> buslinestation1 = new List <BusLineStation>();
            int stationNumber;

            string[] stationaddress1 = new string[42];

            AddAdress(ref stationaddress1);

            for (int i = 0; i < count; i++)
            {
                stationNumber = r.Next(999999);
                buslinestation1.Add(new BusLineStation(stationNumber, stationaddress1[r.Next(42)]));
            }

            foreach (BusLineStation item in buslinestation1)
            {
                buslinestation.Add(item);
            }

            busLine.RouteTheLine = buslinestation1;
            return(busLine);
        }
Example #5
0
        /// <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();
        }