/// <summary> /// Gets a query and returns the suitable flights /// </summary> /// <param name="flightQuery">the query</param> /// <returns>returns the needed flights</returns> public Flights GetFlights(FlightQuery flightQuery) { Flights suitableFlights = new Flights(); foreach (Flight flight in flights) { // Checks if the flight fits the query if (flight.src.Equals(flightQuery.src) && flight.dst.Equals(flightQuery.dst)) { if (flightQuery.date.Equals(flight.date)) { suitableFlights.Add(flight); } } } return(suitableFlights); }
/// <summary> /// Parse the input file - fill the flights database /// </summary> /// <param name="filePath">The input file (get flights)</param> public void ParseTextFile(string filePath) { flights = new Flights(); StreamReader reader = new StreamReader(filePath); string line = reader.ReadLine(); // Read each line and create a new flight while (line != null) { // Create the flight Flight flight = new Flight(); string[] members = line.Split(' '); flight.flightNumber = members[0]; flight.src = members[1]; flight.dst = members[2]; flight.date = DateTime.Parse(members[3]); flight.seats = Convert.ToInt32(members[4]); flight.price = Convert.ToInt32(members[5]); flights.Add(flight); line = reader.ReadLine(); } // Close the file reader.Close(); }