예제 #1
0
        public static void Test()
        {
            MobilePhone gsm = new MobilePhone("Galaxy NOTE", "Samsung");

            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(177), "Pesho"));
            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(77), "Gesho"));
            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(17), "Tosho"));
            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(87), "Pesho"));
            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(107), "Peci", CallType.Received));
            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(207), "Misho"));
            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(123), "Pesho", CallType.Received));
            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(47), "Mama"));
            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(35), "Tosho"));
            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(333), "Misho", CallType.Received));

            Console.WriteLine("Call history:");
            foreach (var call in gsm.CallHistory)
            {
                Console.WriteLine(call);
            }

            Console.WriteLine();
            Console.WriteLine("Total cost: {0}", gsm.CalcCallCost(0.37m, (CallType.Dailed | CallType.Missed | CallType.Received)).ToString("C"));

            Call max    = null;
            var  maxDur = TimeSpan.MinValue;

            foreach (var item in gsm.CallHistory)
            {
                if (item.Duration > maxDur)
                {
                    maxDur = item.Duration;
                    max    = item;
                }
            }

            Console.WriteLine("Max duration call: {0}", max);
            gsm.DelCall(max);
            Console.WriteLine("Total cost without max element: {0}", gsm.CalcCallCost(0.37m, (CallType.Dailed | CallType.Missed | CallType.Received)).ToString("C"));
            Console.WriteLine();

            gsm.ClearCallHistory();
            Console.WriteLine("Call history after clear it:");
            foreach (var call in gsm.CallHistory)
            {
                Console.WriteLine(call);
            }
        }
예제 #2
0
        public static void Test()
        {
            MobilePhone gsm = new MobilePhone("Galaxy NOTE", "Samsung");
            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(177), "Pesho"));
            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(77), "Gesho"));
            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(17), "Tosho"));
            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(87), "Pesho"));
            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(107), "Peci", CallType.Received));
            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(207), "Misho"));
            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(123), "Pesho", CallType.Received));
            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(47), "Mama"));
            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(35), "Tosho"));
            gsm.CallHistory.Add(new Call(DateTime.Now, DateTime.Now.AddSeconds(333), "Misho", CallType.Received));

            Console.WriteLine("Call history:");
            foreach (var call in gsm.CallHistory)
            {
                Console.WriteLine(call);
            }

            Console.WriteLine();
            Console.WriteLine("Total cost: {0}", gsm.CalcCallCost(0.37m, (CallType.Dailed | CallType.Missed | CallType.Received)).ToString("C"));

            Call max = null;
            var maxDur = TimeSpan.MinValue;
            foreach (var item in gsm.CallHistory)
            {
                if (item.Duration > maxDur)
                {
                    maxDur = item.Duration;
                    max = item;
                }
            }

            Console.WriteLine("Max duration call: {0}", max);
            gsm.DelCall(max);
            Console.WriteLine("Total cost without max element: {0}", gsm.CalcCallCost(0.37m, (CallType.Dailed | CallType.Missed | CallType.Received)).ToString("C"));
            Console.WriteLine();

            gsm.ClearCallHistory();
            Console.WriteLine("Call history after clear it:");
            foreach (var call in gsm.CallHistory)
            {
                Console.WriteLine(call);
            }
        }