public static void Main(string[] args)
        {
            // 12. Call history test:
            // Write a class GSMCallHistoryTest to test the call history functionality
            // of the GSM class.
            // - Create an instance of the GSM class.
            // - Add few calls.
            // - Display the information about the calls.
            // - Assuming that the price per minute is 0.37 calculate and print the total
            // price of the calls in the history.
            // - Remove the longest call from the history and calculate the total price again.
            // - Finally clear the call history and print it.

            const decimal priceForMinute = 0.37M;

            GSM mobilePhone = new GSM("Lumia 720", "Nokia", null, "Pesho I. Petrov");

            Console.ForegroundColor = ConsoleColor.White;
            mobilePhone.AddCall("0888 888 888", 37);
            mobilePhone.AddCall("0999 999 999", 79);
            mobilePhone.AddCall("0111 222 222", 189);
            mobilePhone.AddCall("0222 222 222", 163);
            mobilePhone.AddCall("0333 333 333", 245);

            foreach (var call in mobilePhone.CallHistory)
            {
                Console.WriteLine(call);
            }

            Console.WriteLine("The total price is: {0}",
                mobilePhone.TotalPriceOfTheCalls(priceForMinute));

            var longestCall = mobilePhone
                .CallHistory
                .OrderByDescending(x => x.DurationSeconds)
                .FirstOrDefault();

            mobilePhone.DeleteCall(longestCall);

            Console.WriteLine("The total price without longest call is: {0}",
                                    mobilePhone.TotalPriceOfTheCalls(priceForMinute));

            mobilePhone.ClearCallHistory();

            Console.WriteLine();
            Console.WriteLine("Prints all calls to show that history is empty.");

            foreach (var call in mobilePhone.CallHistory)
            {
                Console.WriteLine(call);
            }

            Console.WriteLine();
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            // 07. GSM test:
            // Write a class GSMTest to test the GSM class:
            // Create an array of few instances of the GSM class.
            // Display the information about the GSMs in the array.
            // Display the information about the static property IPhone4S.

            GSM[] mobilePhone = new GSM[3];

            for (int i = 0; i < mobilePhone.Length; i++)
            {
                mobilePhone[i] = new GSM("Lumia 720", "Nokia", 890m, "Pesho I. Petrov",
                    new Battery(72m, 6m, BatteryType.LiIon),
                    new Display(8.7, "16M"));
            }

            mobilePhone[0].Owner = "Ivan P. Ivanov";
            mobilePhone[0].Battery.BatteryType = BatteryType.NiCd;
            mobilePhone[0].Display.NumberOfColors = "32M";
            mobilePhone[0].Battery.HoursIdle = 20m;

            mobilePhone[1].Price = 690.9m;
            mobilePhone[1].Battery.BatteryType = BatteryType.LiPol;
            mobilePhone[1].Display.Size = 6.4;
            mobilePhone[1].Battery.HoursTalk = 12.5m;

            mobilePhone[2] = GSM.IPhone4S;

            Console.ForegroundColor = ConsoleColor.White;

            for (int i = 0; i < mobilePhone.Length; i++)
            {
                Console.WriteLine(mobilePhone[i]);
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.Green + i;
            }
        }