public static void Main() { GSM[] arr = new GSM[5] { new GSM("Lumia", "Nokia", 500, "Ivan"), new GSM("S6", "Samsung", 1000, "Maria"), new GSM("6S", "iPhone", 1500, "Pesho"), new GSM("P6", "Huawei", 690.50, "John"), new GSM("6", "iPhone", 1300, "Ginka") }; foreach (var phone in arr) { Console.WriteLine(phone); } Console.WriteLine(); GSM myGSM = new GSM("Lumia", "Nokia", 500, "Ivan"); myGSM.AddCalls(new Call(60)); myGSM.AddCalls(new Call(120)); myGSM.AddCalls(new Call(20)); myGSM.AddCalls(new Call(10)); for (int i = 0; i < myGSM.CallHistory.Count; i++) { Console.WriteLine("Call {0} duration: {1}sec", i + 1, myGSM.CallHistory[i].DurationInSeconds); } Console.WriteLine(); Console.WriteLine("Total price of all calls: {0}", myGSM.CalculateTotalPriceOfCalls()); int longestCall = int.MinValue; for (int i = 1; i < myGSM.CallHistory.Count; i++) { int currentMax = Math.Max(myGSM.CallHistory[i - 1].DurationInSeconds, myGSM.CallHistory[i].DurationInSeconds); if (longestCall < currentMax) { longestCall = currentMax; } } for (int i = 0; i < myGSM.CallHistory.Count; i++) { if (myGSM.CallHistory[i].DurationInSeconds == 120) { myGSM.CallHistory.RemoveAt(i); } } Console.WriteLine("Total price of all calls after removing longest call : {0}", myGSM.CalculateTotalPriceOfCalls()); myGSM.ClearCallHistory(); for (int i = 0; i < myGSM.CallHistory.Count; i++) { Console.WriteLine("After clear {0}", myGSM.CallHistory[i].DurationInSeconds); } }
static void Main(string[] args) { GSM gsm = new GSM("testModel", "testManufacturer"); gsm.AddCall(new Call("11.02.2013", "18:32", "00000000", 432)); gsm.AddCall(new Call("11.02.2013", "19:02", "00000001", 23)); gsm.AddCall(new Call("12.02.2013", "11:28", "00000010", 5243)); foreach (Call call in gsm.CallHistory) { Console.WriteLine("Call date: " + call.Date); Console.WriteLine("Call time: " + call.Time); Console.WriteLine("Call phone number: " + call.PhoneNumber); Console.WriteLine("Call duration: " + call.Duration); Console.Write("\n"); } Console.WriteLine("Total price: " + gsm.TotalPrice(0.37m)); gsm.DeleteCall(2); Console.WriteLine("Total price without the longest call: " + gsm.TotalPrice(0.37m)); Console.Write("\n"); foreach (Call call in gsm.CallHistory) { Console.WriteLine("Call date: " + call.Date); Console.WriteLine("Call time: " + call.Time); Console.WriteLine("Call phone number: " + call.PhoneNumber); Console.WriteLine("Call duration: " + call.Duration); Console.Write("\n"); } gsm.ClearCallHistory(); foreach (Call call in gsm.CallHistory) { Console.WriteLine("Call date: " + call.Date); Console.WriteLine("Call time: " + call.Time); Console.WriteLine("Call phone number: " + call.PhoneNumber); Console.WriteLine("Call duration: " + call.Duration); Console.Write("\n"); } }
static void CallHistoryTest() { decimal pricePerMinute = 0.37m; Console.WriteLine("Let we test th call history! Ready? ...................\n"); GSM GFlex = new GSM("G-Flex", "LG", (decimal)399.99, "Pavkata", new Battery("G5", 90, 8, BatteryType.LithiumPolymer), new Display((decimal)5.2, 16000000)); GFlex.AddCall(new Calls("01/01/2001", "00:01", "0883654675", 567)); GFlex.AddCall(new Calls("20/07/2013", "22:40", "0894223760", 120)); GFlex.AddCall(new Calls("29/02/2016", "05:10", "0899132465", 221)); GFlex.AddCall(new Calls("16/06/2016", "11:59", "0895386583", 21)); GFlex.AddCall(new Calls("31/06/2016", "06:09", "0877975201", 243)); for (int i = 0; i < GFlex.History.Count; i++) { Console.WriteLine(GFlex.History[i]); } Console.WriteLine("Calls Price: {0:F2}", GFlex.totalPrice(pricePerMinute)); Calls longest = GFlex.History[0]; foreach (var call in GFlex.History) { if (call.CallDuration > longest.CallDuration) { longest = call; } } GFlex.DeleteCall(longest); Console.WriteLine("Calls Price without longest: {0:F2}", GFlex.totalPrice(pricePerMinute)); GFlex.ClearCallHistory(); Console.WriteLine("Call history cleared!"); }
public static void Test() { GSM phone = new GSM("Samsung", "Galaxy S3"); //Add calls GSMCallHistoryTest.Calls = new List<Calls> { new Calls(new DateTime(2015, 03, 17, 10, 32, 23), "0887591529", 35), new Calls(new DateTime(2015, 03, 17, 11, 32, 23), "0887595629", 56), new Calls(new DateTime(2015, 03, 17, 13, 32, 23), "0887576529", 39) }; foreach (Calls call in GSMCallHistoryTest.Calls) { phone.AddCall(call); } GSMCallHistoryTest.PrintInfoCalls(GSM.CallHistory); Console.WriteLine("Total price is {0:F2}", GSM.CalculateTotalPrice(0.37)); RemoveLongestCall(phone, GSM.CallHistory); Console.WriteLine("Total price without the longest call is {0:F2}", GSM.CalculateTotalPrice(0.37)); phone.ClearCallHistory(); }
public static void Test() { GSM phone = new GSM("Samsung", "Galaxy S3"); //Add calls GSMCallHistoryTest.Calls = new List <Calls> { new Calls(new DateTime(2015, 03, 17, 10, 32, 23), "0887591529", 35), new Calls(new DateTime(2015, 03, 17, 11, 32, 23), "0887595629", 56), new Calls(new DateTime(2015, 03, 17, 13, 32, 23), "0887576529", 39) }; foreach (Calls call in GSMCallHistoryTest.Calls) { phone.AddCall(call); } GSMCallHistoryTest.PrintInfoCalls(GSM.CallHistory); Console.WriteLine("Total price is {0:F2}", GSM.CalculateTotalPrice(0.37)); RemoveLongestCall(phone, GSM.CallHistory); Console.WriteLine("Total price without the longest call is {0:F2}", GSM.CalculateTotalPrice(0.37)); phone.ClearCallHistory(); }
public static void CallHistoryTest() { Console.WriteLine("*************Call History Test*************"); //Create an instance of the GSM class. GSM samsung = new GSM("S5", "Samsung", 1000, "Ivancho", new Battery("G2", 50, 5, BatteryType.LiIon), new Display(5, 500000)); //Add few calls. samsung.AddCall(new Call("30/05/2016", "14:06", "0884089756", 104)); samsung.AddCall(new Call("23/01/2015", "12:42", "0883208975", 311)); samsung.AddCall(new Call("31/04/2016", "11:12", "0884589752", 151)); //Display the information about the calls. for (int i = 0; i < samsung.CallHistory.Count; i++) { Console.WriteLine(samsung.CallHistory[i]); } //Assuming that the price per minute is 0.37 calculate and print the total price of the calls in the history. Console.WriteLine("Calls Price: {0:f2}", samsung.GetTotalCallPrice(0.37m)); //Remove the longest call from the history and calculate the total price again. Call longestCall = samsung.CallHistory[0]; foreach (var call in samsung.CallHistory) { if (call.Duration > longestCall.Duration) { longestCall = call; } } samsung.DeleteCall(longestCall); Console.WriteLine("Calls Price without longest: {0:f2}", samsung.GetTotalCallPrice(0.37m)); //Finally clear the call history and print it. samsung.ClearCallHistory(); Console.WriteLine("Call history cleared!"); }