public static void GSMCallHistoryTest() { GSM testCalls = new GSM("WildFire", "HTC", 150, "Ivan", new Battery(BatteryType.LiIon)); testCalls.AddCall(new DateTime(2015, 7, 26, 15, 15, 26), "+359889653420", 88); testCalls.AddCall(new DateTime(2015, 7, 26, 16, 16, 16), "+359824568420", 64); testCalls.AddCall(new DateTime(2015, 7, 26, 15, 31, 59), "+359862487258", 1360); testCalls.AddCall(new DateTime(2015, 7, 26, 16, 0, 10), "+359883426864", 366); Console.WriteLine("Call history"); foreach (var item in testCalls.CallHistory) { Console.WriteLine(item); } Console.WriteLine("Total price for all calls:{0}", testCalls.CallPrice((decimal)0.37)); Console.WriteLine(); Console.WriteLine("After removing the longest call..."); int longestIndex = 0; int time = 0; for (int i = 0; i < testCalls.CallHistory.Count; i++) { if (testCalls.CallHistory[i].Time > time) { time = testCalls.CallHistory[i].Time; longestIndex = i; } } testCalls.DeleteCall(longestIndex); foreach (var item in testCalls.CallHistory) { Console.WriteLine(item); } Console.WriteLine("Total price of call history:{0}", testCalls.CallPrice(0.37m)); Console.WriteLine("Deleting the call history..."); testCalls.CallHistoryClear(); Console.WriteLine(); Console.WriteLine("Call history:"); foreach (var item in testCalls.CallHistory) { Console.WriteLine(item); } }
public void Test() { gsm.AddCall(new Call(new DateTime(2016, 05, 15, 18, 30, 22), "0885 654 213", 100)); gsm.AddCall(new Call(new DateTime(2015, 11, 22, 13, 45, 23), "0888 352 351", 100)); gsm.AddCall(new Call(new DateTime(2016, 09, 19, 15, 30, 44), "0887 424 212", 100)); Console.WriteLine(gsm.CallHistoryInfo()); Console.WriteLine("Total price: {0:F2} BGN", gsm.CallPrice(0.37m)); gsm.RemoveLongestCall(); Console.WriteLine("Now the total price is {0:F2} BGN", gsm.CallPrice(0.37m)); gsm.ClearCallHistory(); Console.WriteLine(gsm.CallHistoryInfo()); }
static void Main() { //create a test instance & add 3 calls var gsmTest = new GSM("nokia", "test model"); gsmTest.AddCall(new Call(new DateTime(2015, 12, 31, 10, 00, 00), "0888123456", 61)); gsmTest.AddCall(new Call(new DateTime(2016, 12, 31, 10, 15, 00), "0888666555", 333)); gsmTest.AddCall(new Call(new DateTime(2017, 01, 01, 00, 00, 01), "0888123456", 60)); //test call price calculations Console.WriteLine("Test call price calculation method\r\n=========================================="); Console.WriteLine("Total Calls Count: {0}", gsmTest.CallHistory.Count); Console.WriteLine("Total Price: {0: 0.00}", gsmTest.CallPrice(0.37M)); Console.WriteLine(); //print initial state of the instance Console.WriteLine("Initial state of the gsmTest object\r\n==========================================\r\n{0}", gsmTest); //delete the longest call int indexLongestCall = -1; int maxSeconds = 0; foreach (var call in gsmTest.CallHistory) { if (call.Duration > maxSeconds) { maxSeconds = (int)call.Duration; indexLongestCall++; } } gsmTest.DeleteCall(indexLongestCall); //print price without longest call Console.WriteLine("\r\nPrice calculation without the longest call\r\n=========================================="); Console.WriteLine("Total Calls Count: {0}", gsmTest.CallHistory.Count); Console.WriteLine("Total Price: {0: 0.00}\r\n", gsmTest.CallPrice(0.37M)); Console.WriteLine("gsmTest object without the longest call\r\n==========================================\r\n{0}", gsmTest); //print the final state of the instance //clear the history gsmTest.ClearHistory(); Console.WriteLine("gsmTest object with cleared history\r\n==========================================\r\n{0}", gsmTest); }
static void Main(string[] args) { var ipPhone6 = new GSM(model: "IP-Phone6", manufacturer: "xApple"); var salamSumng = new GSM(model: "Jalacxy7", manufacturer: "SalamSung"); var listFromSmartPhones = new List<GSM>(); listFromSmartPhones.Add(ipPhone6); listFromSmartPhones.Add(salamSumng); foreach (var phones in listFromSmartPhones) { Console.WriteLine(phones); } var iPhone4s = GSM.IPhone4s; var firstTestCall = new Call() { TimeStart = DateTime.Now, TimeEnd = DateTime.Now.AddMinutes(2), ItsIncomming = false, PhoneNumber = "0043123123" }; var duration = firstTestCall.Duration(); var secondTestCall = new Call() { TimeStart = DateTime.Now, TimeEnd = DateTime.Now.AddMinutes(3), ItsIncomming = false, PhoneNumber = "0043123123" }; ipPhone6.AddCall(firstTestCall); ipPhone6.AddCall(secondTestCall); decimal pricePerMinute = 0.37M; var totalPrice = ipPhone6.CallPrice(pricePerMinute); Console.WriteLine("Total call price: " + totalPrice); }