示例#1
0
        public int CompareTo(object obj)
        {
            BusLine b = (BusLine)obj;

            return(TravelTimeBetweenStations(FirstStation.BusStationKey, LastStation.BusStationKey).CompareTo
                       (b.TravelTimeBetweenStations(b.FirstStation.BusStationKey, b.LastStation.BusStationKey)));
        }
示例#2
0
 public BusLine(BusLine myLine)
 {
     BusLineNumber = myLine.BusLineNumber;
     for (int i = 0; i < myLine.Stations.Count(); i++)
     {
         AddStation(3, myLine.Stations[i].BusStationKey);
     }
     TotalTime = 0;
     foreach (BusLineStation item in Stations)
     {
         TotalTime += item.TravelTime;
     }
 }
示例#3
0
        static void Main(string[] args)
        {
            //Initialization of buses collection
            BusesCollection allBuses = new BusesCollection();

            //creation of 40 stations
            for (int i = 0; i <= 40; i++)
            {
                new BusStation();
            }

            List <int> stations1 = new List <int> {
                2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22
            };
            List <int> stations2 = new List <int> {
                1, 3, 5, 7, 9, 11, 13, 15, 17, 18, 20, 21, 22, 26, 30
            };
            List <int> stations3 = new List <int> {
                3, 6, 9, 12, 15, 18, 21, 24, 30, 34, 38
            };
            List <int> stations4 = new List <int> {
                1, 5, 10, 15, 20, 25, 30, 35, 40, 41
            };
            List <int> stations5 = new List <int> {
                4, 8, 12, 15, 14, 16, 21, 27, 28, 37, 39
            };
            List <int> stations6 = new List <int> {
                2, 8, 9, 15, 12, 13, 23, 29, 32, 36, 39
            };
            List <int> stations7 = new List <int> {
                5, 7, 14, 23, 31, 33, 35, 40
            };
            List <int> stations8 = new List <int> {
                8, 12, 17, 19, 29, 31, 37, 39
            };
            List <int> stations9 = new List <int> {
                1, 6, 10, 11, 18, 23, 24, 30, 40
            };
            List <int> stations10 = new List <int> {
                3, 4, 11, 15, 16, 21, 28, 29, 33, 37, 41
            };

            //creation of 10 lines
            allBuses.Add(3, stations1);
            allBuses.Add(41, stations2);
            allBuses.Add(15, stations3);
            allBuses.Add(6, stations4);
            allBuses.Add(13, stations5);
            allBuses.Add(32, stations6);
            allBuses.Add(74, stations7);
            allBuses.Add(50, stations8);
            allBuses.Add(33, stations9);
            allBuses.Add(1, stations10);



            string choice;

            do
            {
                //menu
                Console.WriteLine("Please choose action you want do :\nAdd an element\n    a1: add a new Bus line\n" +
                                  "    a2: Add a new station in a bus line\nRemove an element\n    b1: Remove a bus line\n    b2:Remove a " +
                                  "station in a bus line\nSearch\n    c1: Search bus lines in station\n    c2: Search the best travel\n" +
                                  "Print\n    d1: Print all bus' lines\n    d2: Print all stations with lines that pass through them\n" +
                                  "e: Exit");
                choice = Console.ReadLine();

                switch (choice)
                {
                case "a1":
                    Console.WriteLine("Please enter number of the new line you want add : ");
                    int line = int.Parse(Console.ReadLine());
                    Console.WriteLine("Please enter list of bus stations in this new line (0 at end) : ");
                    List <int> stations = new List <int>();

                    int oneStation = int.Parse(Console.ReadLine());
                    while (oneStation != 0)
                    {
                        stations.Add(oneStation);
                        oneStation = int.Parse(Console.ReadLine());
                    }

                    try
                    {
                        allBuses.Add(line, stations);
                    }
                    catch (ArgumentException e)
                    {
                        Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message);
                    }
                    Console.WriteLine();
                    break;

                case "a2":
                    BusLine LineToAdd = new BusLine();
                    try
                    {
                        LineToAdd = allBuses[int.Parse(Console.ReadLine())];
                        Console.WriteLine("Please enter station's code to add");
                        int codeStation = int.Parse(Console.ReadLine());
                        Console.WriteLine("Choose where add the new station (1 for start, 2 for middle, 3 for end) : ");
                        LineToAdd.AddStation(int.Parse(Console.ReadLine()), codeStation);
                    }
                    catch (ArgumentException e)
                    {
                        Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message);
                    }
                    break;

                case "b1":
                    BusLine lineToDelete = new BusLine();
                    Console.WriteLine("Please enter number of line to remove : ");
                    try
                    {
                        lineToDelete = allBuses[int.Parse(Console.ReadLine())];
                    }
                    catch (ArgumentException e)
                    {
                        Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message);
                    }
                    allBuses.Remove(lineToDelete);
                    break;

                case "b2":
                    BusLine myLine = new BusLine();
                    Console.WriteLine("Please enter line's number : ");
                    line = int.Parse(Console.ReadLine());
                    Console.WriteLine("Please enter station's code to delete : ");
                    int code = int.Parse(Console.ReadLine());
                    try
                    {
                        myLine = allBuses[line];
                    }
                    catch (ArgumentException e)
                    {
                        Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message);
                    }

                    try
                    {
                        myLine.DeleteStation(code);
                    }
                    catch (ArgumentException e)
                    {
                        Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message);
                    }
                    break;

                case "c1":
                    Console.WriteLine("Please enter line's number : ");
                    List <BusLine> allLinesInStation = allBuses.ListOfLines(int.Parse(Console.ReadLine()));
                    foreach (BusLine item in allLinesInStation)
                    {
                        Console.WriteLine(item.BusLineNumber + " ");
                    }
                    break;

                case "c2":
                    Console.WriteLine("Please enter source's station : ");
                    int statSource = int.Parse(Console.ReadLine());
                    Console.WriteLine("Please enter destination's station : ");
                    int             statDestination = int.Parse(Console.ReadLine());
                    BusesCollection routes          = new BusesCollection();

                    List <BusLine> allLines = allBuses.ListOfLines(statSource);
                    foreach (BusLine item in allLines)
                    {
                        int indexSource      = item.searchStationIndex(statSource);
                        int indexDestination = item.searchStationIndex(statDestination);
                        if (indexDestination >= indexSource)
                        {
                            routes.Add(item.PartOfLine(indexSource, indexDestination));
                        }
                    }
                    if (routes.Empty() == true)
                    {
                        throw new ArgumentException("No line pass trough these 2 stations.");
                    }
                    routes.SortedBusLineList();
                    foreach (BusLine item in routes)
                    {
                        Console.WriteLine(item.ToString());
                    }
                    break;

                case "d1":
                    foreach (BusLine item in allBuses)
                    {
                        Console.WriteLine(item.ToString());
                    }
                    break;

                case "d2":
                    List <BusLine> lines = new List <BusLine>();
                    foreach (BusStation item in ListBusStation.ListOfAllStations)
                    {
                        try
                        {
                            lines = allBuses.ListOfLines(item.BusStationKey);
                            Console.Write(item.BusStationKey + ": ");
                            foreach (BusLine item2 in lines)
                            {
                                Console.Write(item2.BusLineNumber + " ");
                            }
                        }
                        catch (ArgumentException e)
                        {
                            Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message);
                        }

                        Console.WriteLine();
                    }
                    break;

                case "e":
                    break;

                default:
                    break;
                }
            } while (choice != "e");
        }
示例#4
0
 /// <summary>
 /// function Remove - to remove a bus line from collection
 /// </summary>
 /// <param name="myLine">int - num of line to delete</param>
 public void Remove(BusLine myLine)
 {
     BusesLines.Remove(myLine);
 }
示例#5
0
 public void Add(BusLine myLine)
 {
     BusesLines.Add(new BusLine(myLine));
 }