private static void FindLongestCall(ClassGSM phone, ref int bestCall, ref Call longestCall)
 {
     foreach (var item in phone.callHistory)
     {
         if (bestCall < item.Duration.TotalSeconds)
         {
             bestCall = (int)item.Duration.TotalSeconds;
             longestCall = item;
         }
     }
 }
        public static void TestCalls()
        {
            ClassGSM phone = new ClassGSM("N97Mini", "Nokia", 199.98, "SomeOne", new Battery(BatteryType.NiMH, "standart"), new Display(4.5));
            Call currentCall = new Call(DateTime.Now.AddDays(1), "0887654321", 58);
            phone.AddCall(currentCall);

            currentCall = new Call(DateTime.Now.AddMinutes(24D), "0887654321", 258);
            phone.AddCall(currentCall);

            currentCall = new Call(DateTime.Now.AddDays(3), "0887654321", 155);
            phone.AddCall(currentCall);

            PrintCallHistory(phone);
            // > end Call History

            // > price
            Console.WriteLine("Total cost: {0}EU", phone.TotalCostCalls());
            Console.WriteLine("[price of every started minutes is {0} EU/min]", ClassGSM.pricePM);
            Console.WriteLine();

            // > longest call
            int bestCall = -1;
            Call longestCall = new Call("000", 0);

            FindLongestCall(phone, ref bestCall, ref longestCall);
                // > > deleted
            phone.DeleteCall(longestCall);
            Console.WriteLine("The longest call is {0} seconds", bestCall);
            Console.WriteLine(longestCall.ToString());
            Console.WriteLine();
            Console.WriteLine("- TOTAL COST -");
            Console.WriteLine("Total cost: {0}EU", phone.TotalCostCalls());

            Console.WriteLine();
            PrintCallHistory(phone);
        }
示例#3
0
 public void DeleteCall(Call call)
 {
     callHistory.Remove(call);
     // callHistory.RemoveAt() // use to delete concrete call
 }
示例#4
0
        /*
         Problem 10. Add/Delete calls

        Add methods in the GSM class for adding and deleting calls from the calls history.
        Add a method to clear the call history.
        */
        public void AddCall(Call call)
        {
            callHistory.Add(call);
        }