Exemplo n.º 1
0
        public static void ShowGSMTest()
        {
            //create a few instances of the GSM class
            GSM[] phones = new GSM[]
                                {
                                    new GSM("Xperia X10", "Sony", 270, "Petar Petrov",
                                            new Battery("Standard", 400, 20, BatteryType.LiPo),
                                            new Display(4.0, 265000)),

                                    new GSM("Xperia S", "Sony", 350, "Nikolay Dimitrov",
                                            new Battery("Standard", 420, 25, BatteryType.LiIon),
                                            new Display(4.3, 16000000)),

                                    new GSM("Galaxy S3", "Samsung", 700, "Ivan Ivanov",
                                            new Battery("Standard", 450, 30, BatteryType.LiPo),
                                            new Display(4.5, 16000000)),
                                };

            Console.WriteLine("Information about some GSMs: ");
            foreach (var phone in phones)
            {
                Console.WriteLine(phone);
            }

            Console.WriteLine("IPhone 4S Information:\n{0}", GSM.IPhone4S);
        }
        public static void ShowGSMCallHistoryTest()
        {
            GSM gsm = new GSM("Xperia S", "Sony", 350, "Nikolay Dimitrov",
                              new Battery("Standard", 420, 25, BatteryType.LiIon),
                              new Display(4.3, 16000000));

            //fill the call log
            gsm.AddCall(new Call("14.11.2012 12:50", "0888121314", 120));
            gsm.AddCall(new Call("16.11.2012 20:35", "0888156714", 317));
            gsm.AddCall(new Call("17.11.2012 17:21", "0886987651", 135));

            Console.WriteLine("Call history information:");
            foreach (var call in gsm.CallHistory)
            {
                Console.WriteLine("{0}\n", call);
            }

            //calculate total price
            double pricePerMinute = 0.37;
            Console.WriteLine("Total price of the calls: {0}",
                gsm.GetTotalPriceOfCalls(pricePerMinute));

            //get and remove the longest call
            Call longestCall = (from c in gsm.CallHistory
                                orderby c.Duration
                                select c).Last();
            gsm.RemoveCall(longestCall);

            Console.WriteLine("Longest call removed, total price: {0}",
                gsm.GetTotalPriceOfCalls(pricePerMinute));

            //clear call history
            gsm.ClearCallHistory();
            Console.WriteLine("Call history cleared; call history: ");
            foreach (var call in gsm.CallHistory)
            {
                Console.WriteLine("{0}\n", call);
            }
        }