Exemplo n.º 1
0
        static void Main(string[] args)
        {
            int idPessenger = 0;

            Flight[] flights = new Flight[5];
            flights[0] = new Flight("Paris", "Kopenhaga", 1, 5, 2014, "SL321");
            flights[1] = new Flight("Tokyo", "Osaka", 3, 6, 2014, "JA451");
            flights[2] = new Flight("Osaka", "Barcelona", 4, 6, 2014, "EA551");
            flights[3] = new Flight("Rome", "Warsaw", 21, 7, 2014, "WR767");
            flights[4] = new Flight("Warsaw", "Tokyo", 17, 5, 2014, "LOT333");

            Console.WriteLine("Flights List: ");
            Console.WriteLine(flights[0].getFlightInfo("SL321"));
            Console.WriteLine(flights[1].getFlightInfo("JA451"));
            Console.WriteLine(flights[2].getFlightInfo("EA551"));
            Console.WriteLine(flights[3].getFlightInfo("WR767"));
            Console.WriteLine(flights[4].getFlightInfo("LOT333"));
            Console.WriteLine();

            EconomyPassenger[] economyPassengers = new EconomyPassenger [3];
            FirstClassPassenger[] firstClassPassengers = new FirstClassPassenger[3];

            Hashtable passengers = new Hashtable();

            economyPassengers[0] = new EconomyPassenger(idPessenger, "Lionel", "Messi", "+54 444312663", flights[0], "00001"); // ID = 0
            passengers.Add(idPessenger, "EP");
            idPessenger++;

            firstClassPassengers[0] = new FirstClassPassenger(idPessenger, "Yagami", "Akira", "+321 433533222"); // ID = 1
            passengers.Add(idPessenger, "FCP");
            idPessenger++;

            firstClassPassengers[1] = new FirstClassPassenger(idPessenger, "Andrzej", "Kowalski", "+48 723277322", flights[0], "00002"); // ID = 2
            passengers.Add(idPessenger, "FCP");
            idPessenger++;

            firstClassPassengers[1].AddNewTicket(2, flights[1], "00003", 800.0f);
            firstClassPassengers[1].AddNewTicket(2, flights[2], "00004", 1200.0f);

            firstClassPassengers[2] = new FirstClassPassenger(idPessenger, "Jackie", "Chan", "+532 43223444", flights[2], "00005", 32000.0f, 62, "vegetarian dishes"); // ID = 3
            passengers.Add(idPessenger, "FCP");
            idPessenger++;

            economyPassengers[1] = new EconomyPassenger(idPessenger, "Yuna", "Kim", "+442 677727722", flights[1], "00006", 500.0f, 48); // ID = 4
            passengers.Add(idPessenger, "EP");
            idPessenger++;

            economyPassengers[1].AddNewTicket(4, flights[3], "00007", 700.0f);

            economyPassengers[2] = new EconomyPassenger(idPessenger, "Tomasz", "Dziuba", "+48 723333333", flights[4], "00008", 400.0f); // ID = 5
            passengers.Add(idPessenger, "EP");
            idPessenger++;

            economyPassengers[2].AddNewTicket(5, flights[1], "00009", 300.0f);
            economyPassengers[2].AddNewTicket(5, flights[2], "00010", 600.0f);

            Console.WriteLine("Passengers List: ");

            string txt = "";
            IDictionaryEnumerator en = passengers.GetEnumerator();
            while (en.MoveNext())
            {
                if (en.Value.ToString() == "EP")
                {
                    for (int i = 0; i < economyPassengers.Length; i++)
                        txt += economyPassengers[i].GetInfo((int)en.Key);
                }
                else if (en.Value.ToString() == "FCP")
                {
                    for (int i = 0; i < firstClassPassengers.Length; i++)
                        txt += firstClassPassengers[i].GetInfo((int)en.Key);
                }

                if (txt != "")
                {
                    Console.WriteLine(txt);
                    txt = "";
                }
            }
            Console.WriteLine();

            Console.WriteLine("Check Ticket ID: 00001");
            Console.WriteLine(" ----------- ");
            Console.WriteLine(economyPassengers[0].GetTicketInfo(0, economyPassengers, flights, "00001"));
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("Tickets List: ");
            Console.WriteLine(" ----------- ");

            en.Reset();
            while (en.MoveNext())
            {
                if (en.Value.ToString() == "EP")
                {
                    for (int i = 0; i < economyPassengers.Length; i++)
                        txt += economyPassengers[i].GetTicketInfo((int)en.Key, economyPassengers, flights);
                }
                else if (en.Value.ToString() == "FCP")
                {
                    for (int i = 0; i < firstClassPassengers.Length; i++)
                        txt += firstClassPassengers[i].GetTicketInfo((int)en.Key, firstClassPassengers, flights);
                }

                if (txt != "")
                {
                    Console.WriteLine(txt);
                    txt = "";
                }
            }

            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            int idPessenger = 0;

            Flight[] flights = new Flight[5];
            flights[0] = new Flight("Paris", "Kopenhaga", 1, 5, 2014, "SL321");
            flights[1] = new Flight("Tokyo", "Osaka", 3, 6, 2014, "JA451");
            flights[2] = new Flight("Osaka", "Barcelona", 4, 6, 2014, "EA551");
            flights[3] = new Flight("Rome", "Warsaw", 21, 7, 2014, "WR767");
            flights[4] = new Flight("Warsaw", "Tokyo", 17, 5, 2014, "LOT333");

            Console.WriteLine("Flights List: ");
            Console.WriteLine(flights[0].getFlightInfo("SL321"));
            Console.WriteLine(flights[1].getFlightInfo("JA451"));
            Console.WriteLine(flights[2].getFlightInfo("EA551"));
            Console.WriteLine(flights[3].getFlightInfo("WR767"));
            Console.WriteLine(flights[4].getFlightInfo("LOT333"));
            Console.WriteLine();


            EconomyPassenger[]    economyPassengers    = new EconomyPassenger [3];
            FirstClassPassenger[] firstClassPassengers = new FirstClassPassenger[3];

            Hashtable passengers = new Hashtable();

            economyPassengers[0] = new EconomyPassenger(idPessenger, "Lionel", "Messi", "+54 444312663", flights[0], "00001"); // ID = 0
            passengers.Add(idPessenger, "EP");
            idPessenger++;

            firstClassPassengers[0] = new FirstClassPassenger(idPessenger, "Yagami", "Akira", "+321 433533222"); // ID = 1
            passengers.Add(idPessenger, "FCP");
            idPessenger++;

            firstClassPassengers[1] = new FirstClassPassenger(idPessenger, "Andrzej", "Kowalski", "+48 723277322", flights[0], "00002"); // ID = 2
            passengers.Add(idPessenger, "FCP");
            idPessenger++;

            firstClassPassengers[1].AddNewTicket(2, flights[1], "00003", 800.0f);
            firstClassPassengers[1].AddNewTicket(2, flights[2], "00004", 1200.0f);


            firstClassPassengers[2] = new FirstClassPassenger(idPessenger, "Jackie", "Chan", "+532 43223444", flights[2], "00005", 32000.0f, 62, "vegetarian dishes"); // ID = 3
            passengers.Add(idPessenger, "FCP");
            idPessenger++;

            economyPassengers[1] = new EconomyPassenger(idPessenger, "Yuna", "Kim", "+442 677727722", flights[1], "00006", 500.0f, 48); // ID = 4
            passengers.Add(idPessenger, "EP");
            idPessenger++;

            economyPassengers[1].AddNewTicket(4, flights[3], "00007", 700.0f);


            economyPassengers[2] = new EconomyPassenger(idPessenger, "Tomasz", "Dziuba", "+48 723333333", flights[4], "00008", 400.0f); // ID = 5
            passengers.Add(idPessenger, "EP");
            idPessenger++;

            economyPassengers[2].AddNewTicket(5, flights[1], "00009", 300.0f);
            economyPassengers[2].AddNewTicket(5, flights[2], "00010", 600.0f);


            Console.WriteLine("Passengers List: ");

            string txt = "";
            IDictionaryEnumerator en = passengers.GetEnumerator();

            while (en.MoveNext())
            {
                if (en.Value.ToString() == "EP")
                {
                    for (int i = 0; i < economyPassengers.Length; i++)
                    {
                        txt += economyPassengers[i].GetInfo((int)en.Key);
                    }
                }
                else if (en.Value.ToString() == "FCP")
                {
                    for (int i = 0; i < firstClassPassengers.Length; i++)
                    {
                        txt += firstClassPassengers[i].GetInfo((int)en.Key);
                    }
                }

                if (txt != "")
                {
                    Console.WriteLine(txt);
                    txt = "";
                }
            }
            Console.WriteLine();

            Console.WriteLine("Check Ticket ID: 00001");
            Console.WriteLine(" ----------- ");
            Console.WriteLine(economyPassengers[0].GetTicketInfo(0, economyPassengers, flights, "00001"));
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("Tickets List: ");
            Console.WriteLine(" ----------- ");

            en.Reset();
            while (en.MoveNext())
            {
                if (en.Value.ToString() == "EP")
                {
                    for (int i = 0; i < economyPassengers.Length; i++)
                    {
                        txt += economyPassengers[i].GetTicketInfo((int)en.Key, economyPassengers, flights);
                    }
                }
                else if (en.Value.ToString() == "FCP")
                {
                    for (int i = 0; i < firstClassPassengers.Length; i++)
                    {
                        txt += firstClassPassengers[i].GetTicketInfo((int)en.Key, firstClassPassengers, flights);
                    }
                }

                if (txt != "")
                {
                    Console.WriteLine(txt);
                    txt = "";
                }
            }

            Console.ReadLine();
        }