//Task 07 public static void TestGSM() { Console.WriteLine("Testing GSMs:\n"); Battery newBattery = new Battery("Tesla Battery", 300, 10, BatteryType.LiIon); Display newDisplay = new Display(12000000, new int[] { 10, 10 }); GSM motorollaGSM = new GSM("T100", "Motorola", null, null, newBattery, newDisplay); GSM nokiaGSM = new GSM("c101", "Nokia", 20, "Me", new Battery("NokiaBattery"), new Display(2000, new int[] { 32, 64 })); GSM alcatelGSM = new GSM("alcatel", "China"); GSM[] manyGSMs = new GSM[] { motorollaGSM, nokiaGSM, alcatelGSM }; foreach (GSM gsm in manyGSMs) { Console.WriteLine(gsm.ToString()); Console.WriteLine(); } Console.WriteLine("Iphone 4S Info:"); Console.WriteLine(motorollaGSM.IPhone4SInfo.ToString()); }
public static void TestGSMCallHistory() { Console.WriteLine("Testing GSM Call hostory:\n"); GSM myGSM = new GSM("C101", "Finland", 20, "Me", new Battery("LiMion", 200, 8, BatteryType.LiIon), new Display(20000, new int[] { 32, 64 })); Call firstCall = new Call(DateTime.Today, "104123 123 123", 430); Call secondCall = new Call(new DateTime(2013, 01, 31, 22, 43, 22), "102 2313", 120); Call thirdCall = new Call(new DateTime(2013, 1, 23, 12, 30, 04), "12314", 30); myGSM.AddCalltoCallHistory(firstCall); myGSM.AddCalltoCallHistory(secondCall); myGSM.AddCalltoCallHistory(thirdCall); Console.WriteLine(myGSM.PrintCallHistory()); Console.WriteLine("Total call price: " + String.Format("{0:c2}", myGSM.GetCallValue(0.37M))); Console.WriteLine("\nRemoving the longest phone call from History\n"); long longestCallDuration = 0; Call longestCall = null; //Getting the longest Call foreach (Call call in myGSM.CallHistory) { if (call.CallDuration > longestCallDuration) { longestCallDuration = call.CallDuration; longestCall = call; } } //Remove the longest Call myGSM.RemoveCallfromHistory(longestCall); Console.WriteLine("Total Price after removing the longest Call: " + String.Format("{0:c2}", myGSM.GetCallValue(0.37M))); Console.WriteLine("\nClearing Call History."); myGSM.ClearHistory(); Console.WriteLine("\nAfter clearing the history, call history is:"); Console.WriteLine(myGSM.PrintCallHistory()); }
// Tests the CallHistory functionality of the GSM class public static void Test() { GSM gsm = new GSM("Galaxy S IV", "Samsung"); gsm.AddCall(new Call(DateTime.Now, "0876 321 434", 123)); gsm.AddCall(new Call(DateTime.Now.AddHours(30), "+33 898 534 123", 432)); gsm.AddCall(new Call(DateTime.Now.AddHours(5), "+359 234 534 233", 34)); // Displays information about the calls and total price of the calls gsm.CallHistory.ForEach(Console.WriteLine); Console.WriteLine("{0:c2}", gsm.TotalCallCosts(0.37f)); // Finds and deletes the longest call from the history gsm.DeleteCall(gsm.CallHistory.OrderByDescending(x => x.Duration).First()); Console.WriteLine("{0:c2}", gsm.TotalCallCosts(0.37f)); // Clears the call log and prints it gsm.ClearCallHistory(); gsm.CallHistory.ForEach(Console.WriteLine); }