Ejemplo n.º 1
0
 public static string SearchFlight(Flight[] flights, int id)
 {
     int found = 0;
     foreach (Flight f in flights)
     {
         if (f.id.Equals(id))
         {
             found = 1;
             return f.ToString();
         }
     }
     if (found.Equals(0) || found == 0)
         return "No Flights Found";
     return "";
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            // init arrays
            Customer[] customers = new Customer[2]
            {
                new Customer(),
                new Customer()
            };
            Flight[] flights = new Flight[2]
            {
                new Flight(),
                new Flight()
            };

            // add demo data
            customers[0].id = 100;
            //customers[0].name = "John Doe";
            Console.WriteLine("Customer 1 name: ");
            customers[0].name = Convert.ToString(Console.ReadLine());
            customers[0].flight_id = 1000;
            customers[1].id = 200;
            //customers[1].name = "Jane Doe";
            Console.WriteLine("Customer 2 name: ");
            customers[1].name = Convert.ToString(Console.ReadLine());
            customers[1].flight_id = 2000;

            flights[0].id = 1000;
            flights[0].origin = "Honduras";
            flights[0].dest = "Siberia";
            flights[0].date = "2015-01-01";
            flights[1].id = 2000;
            flights[1].origin = "Siberia";
            flights[1].dest = "Honduras";
            flights[1].date = "2016-01-01";

            // print arrays
            Array.ForEach(customers, x => Console.WriteLine(x));
            Array.ForEach(flights, x => Console.WriteLine(x));

            // scan user flight id keyword and search flight array for matches
            Console.WriteLine("Flight search keyword (Hint: 1000 is correct): ");
            int keyword = Convert.ToInt16(Console.ReadLine());
            Console.WriteLine(Flight.SearchFlight(flights, keyword));
            Console.WriteLine(Customer.SearchCustomer(customers, keyword));

            //var results = Array.FindAll(flights, s => s.Equals(keyword));
            //Console.WriteLine(Convert.ToString(results));
            //Console.WriteLine(Convert.ToString(Array.FindAll(flights, s => s.Equals(Convert.ToString(Console.ReadLine())))));
        }