Example #1
0
 public Flight(
     Airplane plane,
     DateTime arrivalDateTime,
     DateTime departureDateTime,
     DateTime arrivedToAirport,
     string arrivalAirport,
     string departureAirport,
     TimeSpan durationOfFlight,
     int numberOfAvailableTickets,
     int gateArrival,
     int gateDeparture)
 {
     ArrivalDateTime      = arrivalDateTime;
     DepartureDateTime    = departureDateTime;
     ArrivedToAirport     = arrivedToAirport;
     ArrivalAirportCode   = arrivalAirport;
     DepartureAirportCode = departureAirport;
     DurationOfFlight     = durationOfFlight;
     Plane = plane;
     NumberOfAvailableTickets = numberOfAvailableTickets;
     GateArrival   = gateArrival;
     GateDeparture = gateDeparture;
 }
Example #2
0
        public static void Main()
        {
            Airplane a = new Airplane();
            Airplane b = new Airplane();
            Airplane c = new Airplane();

            ArrayList list = new ArrayList {
                a, b, c
            };
            Dispatcher dispatcher = new Dispatcher(list);


            a.Land();
            b.Land();
            a.TakeOff();

            Airplane d = new Airplane();

            dispatcher.Add(d);

            d.Land();

            dispatcher.Detach();
        }
Example #3
0
 private Airplane CopyAirplane(Airplane from)
 {
     return(new Airplane(from.Model, from.PriceToBuy, from.PriceToSell, from.PriceToRent, from.PriceToLeasing, from.Carrying, from.PassengerСapacity,
                         from.Wear, from.FuelConsumption, from.Speed, from.RangeFlight, from.AirplaneImage, from.Status, from.Tenancy));
 }
Example #4
0
 public void Add(Airplane airplane)
 {
     airplaneList.Add(airplane);
     (airplaneList[airplaneList.Count - 1] as Airplane).Changed += new Communication(AirplaneAction);
 }
Example #5
0
        public void AddFlight()
        {
            commandLine.Write("Add new flight.");

            if (airplaneManager.AirplanesCount().Equals(0))
            {
                commandLine.Write("Add at least one airplane.");
                return;
            }

            if (airportManager.AirportsCount() < 2)
            {
                commandLine.Write("Add at least two airports.");
                return;
            }

            commandLine.Write("Enter departure airport code:");
            string departureAirportCode = ReadDepartureAirportCode();

            commandLine.Write("Enter departure date:");
            DateTime departureDateTime = ReadDate();

            commandLine.Write("Enter destination airport code:");
            string arrivalAirportCode = ReadArrivalAirportCode(departureAirportCode);

            commandLine.Write("Enter departure gate.");
            int gateDeparture = GetGate(departureAirportCode);

            if (gateDeparture == 0)
            {
                commandLine.Write($"Gates in airport with code {departureAirportCode} are not available.");
                return;
            }

            airportManager.AddOrRemoveOneGate("add", departureAirportCode);

            commandLine.Write("Add airplane:");
            Airplane airplane = airplaneManager.GetAirplane();

            while (airplane == null)
            {
                commandLine.Write($"Airplane doesn't exist. Please enter existing one.");
                airplane = airplaneManager.GetAirplane();
            }

            TimeSpan durationOfFlight = CalculateFlightDuration(departureAirportCode, arrivalAirportCode, airplane.Model.Speed);
            DateTime arrivalDateTime  = CalculateArrivalDate(departureDateTime, durationOfFlight);

            commandLine.Write("Enter date when flight arrived to the airport:");
            DateTime flightArrivedToAirport = ReadDate();

            if (departureDateTime - flightArrivedToAirport < airplane.MaintenanceTime)
            {
                commandLine.Write("Flight is not available. Plane is not ready yet. Maintenance time 2 hours.");
                return;
            }

            commandLine.Write("Enter arrival gate.");
            int gateArrival = GetGate(arrivalAirportCode);

            if (gateArrival == 0)
            {
                commandLine.Write($"Gates in airport with code {arrivalAirportCode} are not available.");
                return;
            }

            airportManager.AddOrRemoveOneGate("delete", arrivalAirportCode);

            int numberOfAvailableTickets = airplane.Model.NumberOfSeats;

            airplane.AirportCode = arrivalAirportCode;
            Flight flight = new Flight(
                airplane,
                arrivalDateTime,
                departureDateTime,
                flightArrivedToAirport,
                arrivalAirportCode,
                departureAirportCode,
                durationOfFlight,
                numberOfAvailableTickets,
                gateArrival,
                gateDeparture);

            flightStore.AddFlight(flight);
            commandLine.Write($"Successfully added flight {flight}");
        }