Exemplo n.º 1
0
        static void Main(string[] args)
        {
            AirlineCompany company = new AirlineCompany("S7");

            company[0] = new Flight("1", "Vaasa", "Helsinki", "01.01.2020", 10.99);
            company[1] = new Flight("2", "Helsinki", "Stockholm", "02.02.2020", 11.99);
            company[2] = new Flight("3", "Stockholm", "Oulu", "03.03.2020", 12.99);
            company[3] = new Flight("4", "Oulu", "Vaasa", "04.04.2020", 13.99);

            Console.WriteLine(company.GetName());
            Console.WriteLine(company.FindFlight("1"));
            Console.WriteLine(company.FindFlight("3"));

            Action <List <Flight>, double> printLowerPriceFlights = (List <Flight> Flights, double Price) =>
            {
                List <Flight> filteredFlights = Flights.FindAll((FlightItem) => (
                                                                    FlightItem.GetPrice() < Price
                                                                    ));

                Console.WriteLine("Displaying flights with price lower than {0:N2}", Price);

                filteredFlights.ForEach((FlightItem) => {
                    Console.WriteLine(FlightItem.GetFlightInfo());
                });
            };

            company.PrintFlightsWithDelegate(printLowerPriceFlights, 13.00);
        }
Exemplo n.º 2
0
        private void BuildWaysFromNode(string dispatchCity, DepartureDays departureDay, TimeSpan departureTime)
        {
            var currentNode = Nodes.Find(node => node.Name == dispatchCity);

            currentNode.IsChecked = true;

            var flightsFromNode = Flights.FindAll(route => route.DispatchCity == dispatchCity);

            foreach (var route in flightsFromNode)
            {
                var bestFlight  = route.FindBestFlight(departureDay, departureTime);
                var arrivalNode = Nodes.Find(node => node.Name == route.ArrivalCity);

                if (arrivalNode.TimeOfRoute > currentNode.TimeOfRoute + bestFlight.FlightTime)
                {
                    /*Костыль с поиском дня следующего вылета*/
                    var timeUntilFlight  = bestFlight.FlightTime - bestFlight.Flight.TakeTimeInAir();
                    var timeOfDeparture  = departureTime + timeUntilFlight;
                    var nextDepartureDay = departureDay;

                    for (var i = 0; i < timeOfDeparture.Days; i++)
                    {
                        nextDepartureDay = nextDepartureDay.Next();
                    }
                    /*--------------------------------------------*/

                    arrivalNode.TimeOfRoute    = currentNode.TimeOfRoute + bestFlight.FlightTime;
                    arrivalNode.RouteToTheNode = new List <GraphFlight>(currentNode.RouteToTheNode);
                    arrivalNode.RouteToTheNode.Add(new GraphFlight(bestFlight.Flight, route, nextDepartureDay, bestFlight.FlightTime));
                }

                Flights.RemoveAll(flights => flights.DispatchCity == currentNode.Name && flights.ArrivalCity == route.ArrivalCity);
                Flights.RemoveAll(flights => flights.DispatchCity == route.ArrivalCity && flights.ArrivalCity == currentNode.Name);
            }

            var nextNode = TakeNodeWithMinTimeOfRoute();

            if (nextNode != null)
            {
                var previousNode  = nextNode.RouteToTheNode[nextNode.RouteToTheNode.Count - 1];
                var departureDate = previousNode.TakeArrivalDate((DepartureDays)previousNode.DepartureDay);
                BuildWaysFromNode(nextNode.Name, departureDate.arrivalDay, departureDate.arrivalTime);
            }
        }