static void Main() { GSM firstPhone = new GSM("HTC 10", "HTC Corporation"); GSM secondPhone = new GSM("Y6", "Huawei", "Pesho"); GSM thirdPhone = new GSM("Nexus 5X", "LG", 1050.99, "Ivan", new Battery("abc", 24, 35), new Display(4, 255)); //Create an array of few instances of the GSM class. GSM[] gsmCollection = { firstPhone, secondPhone, thirdPhone }; //Display the information about the GSMs in the array. foreach (var phone in gsmCollection) { Console.WriteLine(phone); Console.WriteLine(); } //Display the information about the static property IPhone4S. Console.WriteLine(GSM.IPhone4S); Console.WriteLine(); //Create an instance of the GSM class. GSM phoneOne = new GSM("Galaxy S4", "Samsung", 450.99, "M", new Battery("LiIon", 100), new Display(5.0, 16)); //Add few calls. Console.WriteLine("Call a number and enter the duration of the call on the seocnd line (in seconds)"); phoneOne.AddCall(new Calls(Console.ReadLine(),int.Parse(Console.ReadLine()))); Console.WriteLine("Call a number"); phoneOne.AddCall(new Calls(Console.ReadLine(),int.Parse(Console.ReadLine()))); Console.WriteLine("Call a number"); phoneOne.AddCall(new Calls(Console.ReadLine(),int.Parse(Console.ReadLine()))); Console.WriteLine("Call a number"); phoneOne.AddCall(new Calls(Console.ReadLine(),int.Parse(Console.ReadLine()))); Console.WriteLine("Call a number"); phoneOne.AddCall(new Calls(Console.ReadLine(),int.Parse(Console.ReadLine()))); // Display the information about the calls. foreach (var call in phoneOne.CallHistory) { Console.WriteLine($"Date and time of call {call.Date.ToShortDateString()} at {string.Format("{0}:{1}:{2}", call.Time.Hours, call.Time.Minutes, call.Time.Minutes)}. Called number: {call.DailedNum}. Call duration {call.Duration/60d:F3} min."); } double pricePerMin = 0.37; Console.WriteLine("The price of total calls is {0} BGN", phoneOne.CallsTotalPrice(pricePerMin)); phoneOne.RemoveLongestCall(); Console.WriteLine("The price of total calls is {0} BGN", phoneOne.CallsTotalPrice(pricePerMin)); //Finally clear the call history and print it. phoneOne.DeleteCallHistory(); }
public static void Test() { //Create an instance of the GSM class GSM gsm = new GSM("Iphone 5S", "Apple"); //Add few calls gsm.AddCall(new Call(new DateTime(2014, 1, 2, 12, 24, 0), "0889333333", 78)); gsm.AddCall(new Call(new DateTime(2014, 2, 2, 18, 35, 0), "0888230531", 740)); gsm.AddCall(new Call(new DateTime(2014, 3, 2, 18, 01, 0), "112", 1600)); //Display the information about the calls Console.WriteLine(gsm.GetCallHistory()); //Print the total price of the calls in the history Console.WriteLine("Total price: {0:F2}", gsm.CalculatePrice(PricePerMinute)); Console.WriteLine(); //Remove the longest call from the history gsm.CallHistory.RemoveAll(x => x.Duration == gsm.CallHistory.Max(y => y.Duration)); //Calculate the total price again Console.WriteLine("Total price: {0:F2}", gsm.CalculatePrice(PricePerMinute)); //Clear the call history and print it gsm.ClearCallHistory(); Console.WriteLine(); Console.WriteLine(gsm.GetCallHistory()); }
static void Main() { GSM firstPhone = new GSM("HTC 10", "HTC Corporation"); GSM secondPhone = new GSM("Y6", "Huawei", "Pesho"); GSM thirdPhone = new GSM("Nexus 5X", "LG", 1050.99, "Ivan", new Battery("abc", 24, 35), new Display(4, 255)); //Create an array of few instances of the GSM class. GSM[] gsmCollection = { firstPhone, secondPhone, thirdPhone }; //Display the information about the GSMs in the array. foreach (var phone in gsmCollection) { Console.WriteLine(phone); Console.WriteLine(); } //Display the information about the static property IPhone4S. Console.WriteLine(GSM.IPhone4S); Console.WriteLine(); //Create an instance of the GSM class. GSM phoneOne = new GSM("Galaxy S4", "Samsung", 450.99, "M", new Battery("LiIon", 100), new Display(5.0, 16)); //Add few calls. Console.WriteLine("Call a number and enter the duration of the call on the seocnd line (in seconds)"); phoneOne.AddCall(new Calls(Console.ReadLine(), int.Parse(Console.ReadLine()))); Console.WriteLine("Call a number"); phoneOne.AddCall(new Calls(Console.ReadLine(), int.Parse(Console.ReadLine()))); Console.WriteLine("Call a number"); phoneOne.AddCall(new Calls(Console.ReadLine(), int.Parse(Console.ReadLine()))); Console.WriteLine("Call a number"); phoneOne.AddCall(new Calls(Console.ReadLine(), int.Parse(Console.ReadLine()))); Console.WriteLine("Call a number"); phoneOne.AddCall(new Calls(Console.ReadLine(), int.Parse(Console.ReadLine()))); // Display the information about the calls. foreach (var call in phoneOne.CallHistory) { Console.WriteLine($"Date and time of call {call.Date.ToShortDateString()} at {string.Format("{0}:{1}:{2}", call.Time.Hours, call.Time.Minutes, call.Time.Minutes)}. Called number: {call.DailedNum}. Call duration {call.Duration/60d:F3} min."); } double pricePerMin = 0.37; Console.WriteLine("The price of total calls is {0} BGN", phoneOne.CallsTotalPrice(pricePerMin)); phoneOne.RemoveLongestCall(); Console.WriteLine("The price of total calls is {0} BGN", phoneOne.CallsTotalPrice(pricePerMin)); //Finally clear the call history and print it. phoneOne.DeleteCallHistory(); }
public static void Main() { GSM someGSM = new GSM("Xperia M4 Aqua Dual", "Sony", 520.87m, "Sony owner", new Battery("Xperia Aqua Battery", 488, 13.5f, Battery.BatteryType.LiIon), new Display(5f, 16777216)); someGSM.AddCall(new Call(new DateTime(2015, 03, 15, 9, 16, 53), "+359874433434", 67)); someGSM.AddCall(new Call(new DateTime(2015, 02, 16, 18, 3, 7), "+359882223344", 124)); someGSM.AddCall(new Call(new DateTime(2015, 01, 12, 19, 3, 12), "+359898887766", 23)); someGSM.AddCall(new Call(new DateTime(2015, 03, 16, 12, 37, 15), "+359884455566", 85)); someGSM.AddCall(new Call(new DateTime(2015, 03, 17, 16, 43, 0), "+359879933222", 283)); someGSM.AddCall(new Call(new DateTime(2015, 03, 12, 20, 55, 19), "+359897774433", 149)); someGSM.AddCall(new Call(new DateTime(2015, 01, 28, 17, 55, 4), "+359884562233", 508)); Console.WriteLine("Current Calls History:"); foreach (Call item in someGSM.CallsList) { Console.WriteLine("Call time: {0}, Number: {1}, Duration: {2} sec.", item.CallDateTime, item.CallNumber, item.CallDuration); } Console.WriteLine("\nThe total price for the calls is {0}", someGSM.GetCallsPrice(0.37m)); int longestCall = someGSM.CallsList[0].CallDuration; int longestCallIndex = 0; for (int i = 0; i < someGSM.CallsList.Count; i++) { if (someGSM.CallsList[i].CallDuration > longestCall) { longestCall = someGSM.CallsList[i].CallDuration; longestCallIndex = i; } } someGSM.DeleteCall(longestCallIndex); Console.WriteLine("\nThe total price for the calls without the longest call is {0}", someGSM.GetCallsPrice(0.37m)); someGSM.ClearCalls(); Console.WriteLine("\nCleared Calls History:"); foreach (Call item in someGSM.CallsList) { Console.WriteLine("Call time: {0}, Number: {1}, Duration: {2} sec.", item.CallDateTime, item.CallNumber, item.CallDuration); } }