Exemplo n.º 1
0
        static void Main()
        {
            // Array of 5 GSMs
            GSM[] testPhones = new GSM[5];

            // Random generated phones, based on a given pre-set of data
            for (int i = 0; i < 5; i++)
            {
                testPhones[i] = new GSM(company[pickRnd.Next(0, company.Length)],
                    "Model S" + (i + 1), owner[pickRnd.Next(0, owner.Length)],
                    300 + (i * 50), displays[pickRnd.Next(0, displays.Length)],
                    batteries[pickRnd.Next(0, batteries.Length)]);
            }

            // Displaying some information about the phones
            foreach (var phone in testPhones)
            {
                Console.WriteLine("{0} bought a {1} {2} for {3:C}", phone.Owner, phone.Manufacturer, phone.Model, phone.Price);
            }

            Console.WriteLine();

            // sorting the  array by the size of the displays and then by the longest possible hours of talk
            // and finally printing the result

            var sorted = testPhones.OrderByDescending(x => x.Display.DisplaySize)
                .ThenByDescending(y => y.Battery.HoursTalk);

            foreach (var phone in sorted)
            {
                Console.WriteLine("{0} has display of {1}\" and can chat for {2} hours on his {3}"
                    , phone.Owner, phone.Display.DisplaySize, phone.Battery.HoursTalk, phone.Manufacturer);
            }

            // crating Iphone6 from Problem 6
            var testIphone6 = GSM.IPhone_6;

            // printign the full information for Iphone6
            Console.WriteLine(GSM.FullPhoneInfo(testIphone6));
        }