public static void CallHistoryTest() { GSM testGSM = new GSM("GXM-510", "Samsung", "Ivan", 540.50, new Battery("Rx_tgr", new TimeSpan(5, 06, 0, 0), BatteryType.Li_Ion), new Display(256)); testGSM.AddCall(new Call(new DateTime(2014, 05, 03, 22, 45, 15), "+359 887 63 63 27", new TimeSpan(0, 00, 3, 13))); testGSM.AddCall(new Call(new DateTime(2014, 05, 04, 12, 35, 12), "+359 897 54 63 33", new TimeSpan(0, 00, 5, 23))); testGSM.AddCall(new Call(new DateTime(2014, 05, 04, 22, 36, 10), "+359 897 38 91 91", new TimeSpan(0, 00, 6, 22))); testGSM.AddCall(new Call(new DateTime(2014, 05, 05, 11, 01, 12), "+359 897 54 63 33", new TimeSpan(0, 00, 1, 13))); testGSM.DisplayCallsInfo(); Console.WriteLine("The price for the calls is {0:C2}.", GSM.CalculateCallsPrice(testGSM)); double longestCall = 0; int longestCallIndex = 0; for (int i = 0; i < testGSM.CallHistory.Count; i++) { if (testGSM.CallHistory[i].Duration.TotalSeconds > longestCall) { longestCall = testGSM.CallHistory[i].Duration.TotalSeconds; longestCallIndex = i; } } testGSM.DeleteCall(testGSM.CallHistory[longestCallIndex]); Console.WriteLine("The price for the calls is {0:C2}.", GSM.CalculateCallsPrice(testGSM)); testGSM.ClearCallHistory(); testGSM.DisplayCallsInfo(); }
static void Main(string[] args) { GSM[] GSMArray = new GSM[3]; GSMArray[0] = new GSM("GXM-510", "Samsung", "Ivan", 540.50, new Battery("Rx_tgr", new TimeSpan(5, 06, 0, 0), BatteryType.Li_Ion), new Display(256)); GSMArray[1] = new GSM("C3_pr34", "HTC", "Pesho", 40.50, new Battery("Tx-435", new TimeSpan(2, 08, 0, 0), BatteryType.NiCdi), new Display(16)); GSMArray[2] = new GSM("Nexus 4", "LG", "Vlado", 340.50, new Battery("C4-rgd", new TimeSpan(3, 06, 0, 0), BatteryType.Li_Ion), new Display(16000000)); foreach (var phone in GSMArray) { phone.DisplayGSMInfo(); } GSM IPhone = GSM.IPhone4S; IPhone.DisplayGSMInfo(); Console.WriteLine(); GSMCallHistoryTest.CallHistoryTest(); }
public static decimal CalculateCallsPrice(GSM thisGSM) { decimal result = 0; foreach (var call in thisGSM.callHistory) { result += Convert.ToDecimal(call.Duration.TotalSeconds) * callPricePerSecond; } return result; }