public static void GSMCallHistoryStartTest() { Console.WriteLine("Call history test"); DrawLine('-'); var testGsm = new GSM("iPhone 18s", "Apple", 1800m, "Batman"); Random rndCallLengthGen = new Random(); Random rndNumberGen = new Random(); for (int i = 0; i < 10; i++) { string number = "+359" + rndNumberGen.Next(82000001, 90000000); uint callDuration = (uint)rndCallLengthGen.Next(8, 361); var call = new Call(callDuration, number); testGsm.AddCall(call); } PrintCallHistory(testGsm); Console.WriteLine("Total calls price: {0:f2}", testGsm.GetCallsPrice(0.37m)); Call logestCall = testGsm.CallHistory.OrderByDescending(c => c.Duration).FirstOrDefault(); testGsm.DeleteCall(logestCall); Console.WriteLine("Total calls price after deleting the longest call: {0:f2}", testGsm.GetCallsPrice(0.37m)); testGsm.ClearCallHistory(); PrintCallHistory(testGsm); }
static void Main(string[] args) { var calls = new Call[] { new Call(DateTime.Now, TimeSpan.FromSeconds(52), "3598873629", 15), new Call(DateTime.Now, TimeSpan.FromSeconds(23), "3598546846", 25), new Call(DateTime.Now, TimeSpan.FromSeconds(45), "3597994516", 35) }; var gsm = new GSM("6", "Nexus"); gsm.AddCall(calls[0]); gsm.AddCall(calls[1]); gsm.AddCall(calls[2]); foreach (var call in gsm.CallHistory) { Console.WriteLine(call); } Console.WriteLine(gsm.CalculateTotalPrice(0.37m)); gsm.DeleteCall(calls[2]); Console.WriteLine(gsm.CalculateTotalPrice(0.37m)); gsm.ClearCall(); Console.WriteLine(gsm.CalculateTotalPrice(0.37m)); }
static void Main(string[] args) { try { //Create battery and display for the GSM Battery battery = new Battery("BL-5C",360,7,Battery.BatteryType.LithiumLon); Display display = new Display(3,65536); //Create GSM GSM gsm = new GSM("1208", "nokia", 50, "Georgi", battery, display); //Console.WriteLine(gsm.ToString()); //Print GSM data //Mace some calls and print the history gsm.AddCall(new Call(new DateTime(2013, 02, 22, 19, 01, 22), "00359888888888", 200)); gsm.AddCall(new Call(new DateTime(2013,02,22,20,02,33),"0887888888",302)); gsm.AddCall(new Call(new DateTime(2013, 02, 22, 20, 30, 19), "0889-88-88-88", 178)); gsm.PrintCallHistiry(); //Calculate the price of all calls decimal price = 0.37m; gsm.CalculateTotalCallsPrice(price); //Remove the longest call and calculate the price again gsm.DeleteCall(1); //The calls in the list start from 0, so the second call(longest) is 1 gsm.CalculateTotalCallsPrice(price); //Clear the history and print it gsm.ClearCallHistory(); gsm.PrintCallHistiry(); } catch (Exception ex) { Console.WriteLine("Error!"+ex.Message); } }
public static void Test() { try { GSM Samsung = new GSM("Samsung S4", "Samsung", 1200, "Ivan", BatteryTypes.Lilon, 140, 23, 4.7, 512000); Samsung.AddCall(new Call("28.8.2013", "14:12:12", "+359125135123", 234)); Samsung.AddCall(new Call("23.8.2013", "14:12:12", "+359125135123", 54)); Samsung.AddCall(new Call("22.8.2013", "12:12:12", "+359125135123", 5234)); Samsung.AddCall(new Call("25.8.2013", "19:12:12", "+359125135123", 34)); Samsung.AddCall(new Call("22.8.2013", "14:0:12", "+359125135123", 2234)); Console.WriteLine("Call history:"); foreach (Call call in Samsung.CallHistory) { Console.WriteLine(call.ToString()); } Console.WriteLine("\nTotal price of calls:" + Samsung.CalculateTotalPrice().ToString() + " lv"); Samsung.DeleteCall(new Call("22.8.2013", "12:12:12", "+359125135123", 5234)); Console.WriteLine("\nTotal price of calls after removing longest call:" + Samsung.CalculateTotalPrice().ToString() + " lv"); Samsung.ClearCallHistory(); Console.WriteLine("\nCall history after clearing it:"); foreach (Call call in Samsung.CallHistory) { Console.WriteLine(call.ToString()); } } catch (Exception e) { Console.WriteLine(e.Message); } }
public static void Start() { // TODO GSM phone = new GSM("Pixel", "Google"); phone.AddCall("+359 123-456", new DateTime(2018, 7, 22), new TimeSpan(0, 1, 15)); phone.AddCall("089123456", new DateTime(2018, 6, 17), new TimeSpan(0, 3, 20)); phone.AddCall("+12 3123 121", new DateTime(2017, 1, 22), new TimeSpan(1, 5, 0)); foreach (Call call in phone.CallHistory) { Console.WriteLine($"Phone: {call.PhoneNumber}, Call Date: {call.Date}, Duration: {call.Duration}"); } PrintBill(phone); // Remove longest call from history Call longestCall = new Call("", new DateTime(), new TimeSpan(-1)); foreach (Call call in phone.CallHistory) { if (call.Duration.Seconds > longestCall.Duration.Seconds) { longestCall = call; } } phone.DeleteCall(longestCall); PrintBill(phone); }
static void Main(string[] args) { GSM phone = new GSM("lala", "sumsAng", "batman", 10000.99); phone.MakeCall(DateTime.Now, "0899999999", 3.44); phone.MakeCall(DateTime.Now.AddHours(3), "0899999999", 3.44); phone.MakeCall(DateTime.Now.AddDays(99), "0889666999", 9.44); phone.MakeCall(DateTime.Now.AddDays(5).AddHours(10), "0009666999", 9.44); Console.WriteLine("Calls ordered by date: "); foreach (DateTime timeOfCall in phone.GetCallsByDate()) { Console.WriteLine(timeOfCall.ToString()); } phone.DeleteCall(2); Console.WriteLine("New calls: "); foreach (DateTime timeOfCall in phone.GetCallsByDate()) { Console.WriteLine(timeOfCall.ToString()); } phone.ClearCallHistory(); Console.WriteLine("\nNothing will show, because history is deleted: "); foreach (DateTime timeOfCall in phone.GetCallsByDate()) { Console.WriteLine(timeOfCall.ToString()); } }
static void Main(string[] args) { try { //Create battery and display for the GSM Battery battery = new Battery("BL-5C", 360, 7, Battery.BatteryType.LithiumLon); Display display = new Display(3, 65536); //Create GSM GSM gsm = new GSM("1208", "nokia", 50, "Georgi", battery, display); //Console.WriteLine(gsm.ToString()); //Print GSM data //Mace some calls and print the history gsm.AddCall(new Call(new DateTime(2013, 02, 22, 19, 01, 22), "00359888888888", 200)); gsm.AddCall(new Call(new DateTime(2013, 02, 22, 20, 02, 33), "0887888888", 302)); gsm.AddCall(new Call(new DateTime(2013, 02, 22, 20, 30, 19), "0889-88-88-88", 178)); gsm.PrintCallHistiry(); //Calculate the price of all calls decimal price = 0.37m; gsm.CalculateTotalCallsPrice(price); //Remove the longest call and calculate the price again gsm.DeleteCall(1); //The calls in the list start from 0, so the second call(longest) is 1 gsm.CalculateTotalCallsPrice(price); //Clear the history and print it gsm.ClearCallHistory(); gsm.PrintCallHistiry(); } catch (Exception ex) { Console.WriteLine("Error!" + ex.Message); } }
public static void TestCallHistory() { // Initializing batteries and displays outside of the GSM constructors, // as the constructors should not initialize anyhting (good practice). var battery = new Battery("Toshiba", BatteryType.Li_Ion, 15, 10); var display = new Display(5.2, 24000); var phone = new GSM("Galaxy S7", "Samsung", 700, "Pesho", battery, display); phone.AddCall(new Call(DateTime.Now, "0999999999", 60)); phone.AddCall(new Call(new DateTime(2016, 7, 12, 23, 58, 30), "0444444444", 60)); phone.AddCall(new Call(new DateTime(2016, 3, 2, 5, 50, 40), "0888888888", 120)); Console.WriteLine("CALL HISTORY:"); Console.WriteLine(phone.DisplayCallHistory() + "\n"); Console.WriteLine("TOTAL PRICE: {0:C2}", phone.GetPrice()); Console.WriteLine(new string ('-', 20)); // Removing longest call and re-calculating price var longestCallIndex = 0; for (int i = 1; i < phone.CallHistory.Count; i++) { if (phone.CallHistory[i].Duration > phone.CallHistory[i - 1].Duration) { longestCallIndex = i; } } phone.DeleteCall(longestCallIndex); Console.WriteLine("MODIFIED CALL HISTORY:"); Console.WriteLine(phone.DisplayCallHistory() + "\n"); Console.WriteLine("NEW TOTAL PRICE: {0:C2}", phone.GetPrice()); }
static void Main() { GSM NokiaN92 = new GSM("Nokia", "N82", 190, "Pesho Gosho", new Battery(Battery.Type.NiCD, 150, 13.5), new Display(2.5, 2000000000)); Console.WriteLine("Add some calls..."); NokiaN92.AddCall("0892023111", 250, 2013, 2, 25, 21, 9, 3); NokiaN92.AddCall("0892023111", 50, 2013, 2, 22, 12, 2, 30); NokiaN92.AddCall("0892023111", 110, 2013, 1, 7, 18, 3, 12); Console.WriteLine("Print the calls:"); foreach (var item in NokiaN92.CallHistory) { Console.WriteLine(item); } Console.WriteLine("Calculate price of calls if the price per minute is 0.37: {0}", NokiaN92.TotalCallsPrice((decimal)0.37)); Console.WriteLine("Deleting longest call duration with the method .DeleteCall(Call)"); NokiaN92.DeleteCall(NokiaN92.CallHistory[0]); Console.WriteLine("Calculate price of calls if the price per minute is 0.37: {0}", NokiaN92.TotalCallsPrice((decimal)0.37)); Console.WriteLine("Clear the CallHistory and print it:"); NokiaN92.ClearCallHistory(); foreach (var item in NokiaN92.CallHistory) { Console.WriteLine(item); } }
static void Main(string[] args) { GSM phone = new GSM("lala", "sumsAng", "batman", 10000.99); phone.MakeCall(DateTime.Now, "0899999999", 3.44); phone.MakeCall(DateTime.Now.AddHours(3), "0899999999", 3.44); phone.MakeCall(DateTime.Now.AddDays(99), "0889666999", 9.44); phone.MakeCall(DateTime.Now.AddDays(5).AddHours(10), "0009666999", 9.44); Console.WriteLine("Calls ordered by date: "); foreach (DateTime timeOfCall in phone.GetCallsByDate()) { Console.WriteLine(timeOfCall.ToString()); } phone.DeleteCall(2); Console.WriteLine("New calls: "); foreach (DateTime timeOfCall in phone.GetCallsByDate()) { Console.WriteLine(timeOfCall.ToString()); } phone.ClearCallHistory(); Console.WriteLine("\nNothing will show, because history is deleted: "); foreach (DateTime timeOfCall in phone.GetCallsByDate()) { Console.WriteLine(timeOfCall.ToString()); } }
private static void CallsInfo() { // 12. Test the call history functionality of the GSM class. GSM gsm = new GSM("Optimus", "LG"); // 12.1 Create an instance of the GSM class. // 12.2 Add few calls. gsm.AddCall(DateTime.Now, 0871111111, 60); gsm.AddCall(DateTime.Now, 0882222222, 200); gsm.AddCall(DateTime.Now, 0893333333, 1234); // 12.3 Display the information about the calls. gsm.PrintHistory(); /* 12.4 Assuming that the price per minute is 0.37 Calculate and print the total price of the calls in the history. */ Console.WriteLine("The cost of calls is: {0:C2}", gsm.CallPrice(0.37f)); // 12.5 Remove the longest call from the history and calculate the total price again. gsm.DeleteCall(1234); Console.WriteLine("The cost of calls without the longest one is: {0:C2}", gsm.CallPrice(0.37f)); // 12.6 Finally clear the call history and print it. gsm.ClearHistory(); gsm.PrintHistory(); Console.WriteLine("History is cleared!" + Environment.NewLine); Main(); }
static void Main() { GSM nokia = new GSM("N73", "Nokia", "Pesho", 360, new Battery("BP-6M", 370, 6, BatteryType.LiIon), new Display(2.4, 243000)); GSM samsung = new GSM("GalaxyS III", "Samsung", "Gosho", 819, new Battery("HR32", 790, 50, BatteryType.LiIon), new Display(4.8, 16000000)); GSM sonyEricsson = new GSM("Xperia Z", "Sony Ericsson", "Kiro", 864, new Battery("PM63", 550, 40, BatteryType.LiIon), new Display(5, 16000000)); GSM vertu = new GSM("Ascent", "Vertu", "Dimcho", 10400, new Battery("RP-M4", 150, 4, BatteryType.LiIon), new Display(0.87, 6)); GSM[] mobilePhones = { nokia, samsung, sonyEricsson, vertu, GSM.IPhone4S }; foreach (var phone in mobilePhones) { Console.WriteLine(phone); Console.WriteLine("------------------------------"); } Call callOne = new Call("0885131618", 125); Call callTwo = new Call("0886933601", 563); Call callThree = new Call("0886948266", 256); vertu.AddCall(callOne); vertu.AddCall(callTwo); vertu.AddCall(callThree); Console.WriteLine("Total price of all calls: {0}", vertu.CalcPriceOfCalls(0.37)); double maxDuration = 0; string number = ""; foreach (var call in vertu.CallHistory) { if (maxDuration < call.Duration) { maxDuration = call.Duration; number = call.DialedPhoneNumber; } } Call longestCall = new Call(number, maxDuration); Console.WriteLine("The longest call lasted {0} seconds and it is made with number {1}.", maxDuration, number); vertu.DeleteCall(longestCall); Console.WriteLine("Now the longest call is removed from the call history."); Console.WriteLine("New total price of all calls: {0}", vertu.CalcPriceOfCalls(0.37)); vertu.ClearCallHistory(); Console.WriteLine("Call history is now cleared!!!"); }
static void Main() { GSM nokia = new GSM("N7", "Nokia"); nokia.AddCall(360); nokia.AddCall(500); nokia.AddCall(1500); nokia.DisplayCalls(); Console.WriteLine("The total price of the calls with 0.37st/min is {0}", nokia.CallPrice(0.37)); nokia.DeleteCall(1500); nokia.DisplayCalls(); Console.WriteLine("The total price of the calls without the longest call is {0}", nokia.CallPrice(0.37)); }
static void Main() { try { //adding battery type i the battery constructor Battery batteryOne = new Battery("SameModel", 10, 20, BatteryType.LiIon); Console.WriteLine("-------------------------EX3---------------------------"); Console.WriteLine(batteryOne.Type); // creating phone Display displayOne = new Display(55f); GSM gsm = new GSM("55k33", "Nokia", 666, "Nqkoi", batteryOne, displayOne); // test for override method ToString() Console.WriteLine("-------------------------EX4---------------------------"); Console.WriteLine(gsm.ToString()); Console.WriteLine("-------------------------EX.7--------------------------"); //creating object test GSMTests test = new GSMTests(); test.Tests();//call its method It is void method so it will directly write the data //ex.9 Console.WriteLine("------------------------EX9---------------------------"); string dateTime ="22.12.2013 01.05.35"; DateTime day = DateTime.ParseExact(dateTime, "dd.MM.yyyy HH.mm.ss", CultureInfo.InvariantCulture);//date string dateTime2 = "20.12.2013 01.05.35"; DateTime day2 = DateTime.ParseExact(dateTime2, "dd.MM.yyyy HH.mm.ss", CultureInfo.InvariantCulture);//date Call firstCall = new Call(day,"0555555555",78); Call secondCall = new Call(day2, "0555555555", 105); Console.WriteLine(firstCall.DateAndTime); gsm.AddCalls(firstCall); gsm.AddCalls(secondCall); Console.WriteLine(); Console.WriteLine(gsm.CallHistory[0].DateAndTime); Console.WriteLine(gsm.CallHistory[1].DateAndTime); Console.WriteLine("------------------------EX10--------------------------"); gsm.DeleteCall(secondCall); for (int i = 0; i < gsm.CallHistory.Count; i++) { Console.WriteLine(gsm.CallHistory[i].DateAndTime); } gsm.ClearCallHistory(); Console.WriteLine("There is {0} call in the call history",gsm.CallHistory.Count); Console.WriteLine("--------------------------EX12------------------------"); GSMCallHistoryTest testHistory = new GSMCallHistoryTest(); testHistory.GSMCallHistoryTests(); } catch (ArgumentException exep) { Console.WriteLine("There is incorrect data!"); Console.WriteLine(exep.ToString()); } }
public static void Main() { // Create the phone GSM myPhone = new GSM("Nexus 5", "Google"); Console.WriteLine("Your phone: {0} {1}\n", myPhone.Manufacturer, myPhone.Model); // Let's make some random calls int numCalls = 5; Random rand = new Random(); int callNumber; int callDuration; for (int i = 0; i < numCalls; i++) { callNumber = rand.Next(884000000, 899999999); callDuration = rand.Next(30, 300); myPhone.OpenCall("+359" + callNumber); myPhone.CloseCall(callDuration); } // Display the call history DisplayCallHistory(myPhone); // Display total cost of all calls decimal pricePerMinute = 0.37m; PrintTotalCost(myPhone, pricePerMinute); // Get the longest call int longestCallIndex = 0; for (int i = 0; i < myPhone.CallHistory.Count; i++) { if (myPhone.CallHistory[i].Duration > myPhone.CallHistory[longestCallIndex].Duration) { longestCallIndex = i; } } // Remove the longest call myPhone.DeleteCall(longestCallIndex); // Display total cost of all calls Console.WriteLine("\nAfter removing the longest call from the history:"); PrintTotalCost(myPhone, pricePerMinute); // Clear the call history and print it. Console.WriteLine("\nClear call history..."); myPhone.ClearCallHistory(); Console.WriteLine(); DisplayCallHistory(myPhone); }
static void Main() { GSM phone1 = new GSM("Samsung", "Germany", 1000); GSM phone2 = new GSM("Nokia", "Italy", 200.99m, "Boris"); GSM phone3 = GSM.IPhone4S; GSM[] phones = new GSM[] { phone1, phone2, phone3 }; Call newCall1 = new Call("05.03.2013", "0882203628", 100); Call newCall2 = new Call("01.02.2013", "11:00", "0882203628", 60); Call newCall3 = new Call("0882203628", 10); Call newCall4 = new Call("08.03.2013", "21:00", "0882203628", 360); phone1.AddCall(newCall1); phone1.AddCall(newCall2); phone1.AddCall(newCall3); phone1.AddCall(newCall4); //Print CallHistory StringBuilder result = new StringBuilder(); foreach (var call in phone1.CallHistory) { result.AppendFormat("Date: {0}\nTime: {1}\nDialedNumber: {2}\nDuration (in seconds): {3}\n\n", call.date, call.time, call.dialedPnoneNumber, call.duration); } Console.WriteLine(result.ToString()); //Calculate TotalPrice decimal price = phone1.TotalPrice(0.37m); Console.WriteLine("{0:F2}лв.", price); //Calculate TotalPrice without long call phone1.DeleteCall(newCall4); decimal priceWithoutLongCall = phone1.TotalPrice(0.37m); Console.WriteLine("{0:F2}лв.", priceWithoutLongCall); //Clear CallHistory phone1.ClearCallHistory(); StringBuilder resultClear = new StringBuilder(); foreach (var call in phone1.CallHistory) { resultClear.AppendFormat("Date: {0}\nTime: {1}\nDialedNumber: {2}\nDuration (in seconds): {3}\n\n", call.date, call.time, call.dialedPnoneNumber, call.duration); } Console.WriteLine(); Console.WriteLine("The result after clear is: \n", resultClear.ToString()); }
public static void Main(string[] args) { // Task 4 GSM testGsm = new GSM("3310", "Nokia", 99.99m, "Pesho", "Nokia Battery", default(BatteryType), "14:45:00", "19:30:00", 2.4f, 8); Console.WriteLine(testGsm + "\n"); // Task 5 Console.WriteLine(GSM.Iphone4S + "\n"); // Task 7 GSM[] gsmArray = new GSM[5]; for (int index = 0; index < gsmArray.Length; index++) { gsmArray[index] = new GSM( string.Format("TestGsm{0}", index), string.Format("Manufacturer{0}", index), index * 100, string.Format("Owner{0}", index), string.Format("Type{0}", index), default(BatteryType)); } foreach (var gsm in gsmArray) { Console.WriteLine(gsm + "\n"); } // Task 10 testGsm.AddCall(new DateTime(2013, 02, 25), "977 977 456", 45); testGsm.AddCall(new DateTime(2013, 02, 27), "966 968 945", 54); testGsm.AddCall(); testGsm.AddCall(new DateTime(2013, 02, 28), "977 555 080", 10); testGsm.DeleteCall(2); // Task 11 Console.WriteLine(testGsm.CallHistory); Console.WriteLine("Total price of calls {0:0.00}$", testGsm.TotalPrice()); // Task 12 testGsm.RemoveLongestCall(); Console.WriteLine("Total price of calls {0:0.00}$", testGsm.TotalPrice()); testGsm.ClearCallHistory(); Console.WriteLine(testGsm.CallHistory); }
static public void Print() { GSM phone = new GSM("galaxy", "samsung"); string date1 = "07/07/2011 10:48:12"; string date2 = "17/03/2012 08:43:08"; string date3 = "08/06/2012 02:52:24"; Call call1 = new Call(ParseDate(date1).ToString("dd/MM/yyyy"), ParseDate(date1).ToString("hh:mm:ss"), 0898456456, 450); Call call2 = new Call(ParseDate(date2).ToString("dd/MM/yyyy"), ParseDate(date2).ToString("hh:mm:ss"), 0898324456, 350); Call call3 = new Call(ParseDate(date3).ToString("dd/MM/yyyy"), ParseDate(date3).ToString("hh:mm:ss"), 0898324879, 620); Console.WriteLine(call1); Console.WriteLine(new string('-', 20)); Console.WriteLine(call2); Console.WriteLine(new string('-', 20)); Console.WriteLine(call3); phone.AddCall(call1); phone.AddCall(call2); phone.AddCall(call3); decimal sum = phone.CalculateTotalPriceOfCalls(phone.CallHistory); Console.WriteLine("price of all calls in History is {0}", sum); ulong maxDuration = 0; int maxIndex = -1; for (int i = 0; i < phone.CallHistory.Count; i++) { if (maxDuration < phone.CallHistory[i].Duration) { maxDuration = phone.CallHistory[i].Duration; maxIndex = i; } } phone.DeleteCall(phone.CallHistory[maxIndex]); sum = phone.CalculateTotalPriceOfCalls(phone.CallHistory); Console.WriteLine("price of all calls in History is {0}", sum); phone.ClearCallHistory(); Console.WriteLine("there are {0} calls in call history", phone.CallHistory.Count); //Console.WriteLine(call1.Date + " " + call1.Time + " " + call1.DialedNumber + " " + call1.Duration); }
static void Main(string[] args) { GSM[] gsmDevices = new GSM[5]; gsmDevices[0] = new GSM( "N95", "Nokia", 650.60m, "Kukata", new Display(15, 65000), new Battery("Takashi", Battery.BatteryType.NiMH, 0, 0)); gsmDevices[1] = new GSM("Touch Pro 2", "HTC", "VGeorgiev"); gsmDevices[2] = new GSM("Galaxy", "Samsung", "Penka"); gsmDevices[3] = new GSM("Touch Diamond", "HTC", "Stoki"); gsmDevices[4] = new GSM(); for (int i = 0; i < gsmDevices.Length; i++) { Console.WriteLine("Manufacturer: {0} , Model: {1}", gsmDevices[i].Manufacturer, gsmDevices[i].Model); } Console.WriteLine(); Console.WriteLine(GSM.IPhone4S.ToString()); // CAll i var device = new GSM("Touch Pro 2", "HTC", "Vlado"); Call firstCall = new Call(DateTime.Now, 180); Call secondCall = new Call(DateTime.Now, 560); Call thirdCall = new Call(DateTime.Now, 340); device.AddCall(firstCall); device.AddCall(secondCall); device.AddCall(thirdCall); device.DeleteCall(firstCall); Console.WriteLine("Call duration: {0}s, Call price: {1:c}", device.CallHistoryDuration(), device.CallHystoryPrice()); GSM.IPhone4S.Owner = "Pesho"; Console.WriteLine(GSM.IPhone4S.Owner); }
//12.Write a class GSMCallHistoryTest to test the call history functionality of the GSM class. //-Create an instance of the GSM class. //-Add few calls. //-Display the information about the calls. //-Assuming that the price per minute is 0.37 calculate and print the total price of the calls in the history. //-Remove the longest call from the history and calculate the total price again. //-Finally clear the call history and print it. static void Main() { const decimal callPerMinutePrice = 0.37M; GSM phone = new GSM("Galaxy S2", "Samsung", 450, "Gogo", new Battery("A1920", BatteryType.LiIon), new Display(3.2M, 100000UL)); phone.AddCall(new Call("29.02.2012", "10:10:10", "0845333444", 60)); phone.AddCall(new Call("15.12.2013", "12:00:00", "0879123456", 480)); phone.AddCall(new Call("20.07.2011", "15:00:00", "0863123456", 960)); //print every call information foreach (Call call in phone.CallHistory) { Console.WriteLine(call.ToString()); Console.WriteLine(); } decimal phoneCallsPrice = phone.CalculateCallsPrice(callPerMinutePrice); Console.WriteLine("Total cost of all calls: {0}", phoneCallsPrice); Console.WriteLine(); phone.DeleteCall(2); phoneCallsPrice = phone.CalculateCallsPrice(callPerMinutePrice); Console.WriteLine("Total cost of all calls after deleted the longest call: {0}", phoneCallsPrice); Console.WriteLine(); //after the deleted call Console.ForegroundColor = ConsoleColor.Cyan; foreach (var call in phone.CallHistory) { Console.WriteLine(call.ToString()); Console.WriteLine(); } phone.ClearCallHistory(); //try to print calls, but history is deleted //there is no calls in the call history and nothing happens foreach (var call in phone.CallHistory) { Console.WriteLine(call.ToString()); Console.WriteLine(); } Console.ResetColor(); }
static void Main(string[] args) { //Create an instance of the GSM class. Battery phoneBattery = new Battery("NiCd", 30.6, 5.6); Display phoneDisplay = new Display(5.0, 16000000); GSM phone = new GSM("Galaxy Note", "Samsung", 866, "Goran Bregovic", phoneBattery, phoneDisplay); //Add few calls. DateTime dateAndTime = new DateTime(2013, 3, 5, 11, 59, 59); Call callOne = new Call(dateAndTime, "0888455455", 110); Call callTwo = new Call(dateAndTime, "0899455455", 50); Call callThree = new Call(dateAndTime, "0886455455", 230); phone.AddCall(callOne); phone.AddCall(callTwo); phone.AddCall(callThree); //Display the information about the calls. //Assuming that the price per minute is 0.37 calculate and print the total price of the calls in the history. Console.WriteLine(phone.CallHistoryToString); double price = phone.CalculatePrice(0.37); Console.WriteLine("The price for the whole history is {0}", price); //Remove the longest call from the history and calculate the total price again. uint maxDuritation = uint.MinValue; Call callToRemove = new Call(dateAndTime, "0886455455", 0); for (int i = 0; i < phone.CallHistory.Count; i++) { if (phone.CallHistory[i].Duritation > maxDuritation) { maxDuritation = phone.CallHistory[i].Duritation; callToRemove = phone.CallHistory[i]; } } phone.DeleteCall(callToRemove); price = phone.CalculatePrice(0.37); Console.WriteLine("The new price after we removed the longest call is {0}", price); //Finally clear the call history and print it. Console.WriteLine(); Console.WriteLine("Clearing History..."); phone.ClearHistory(); Console.WriteLine("Call History: {0}", phone.CallHistoryToString); }
public static void TestCallHistory() { GSM gsm = new GSM("Samsung Galaxy S Duos S7582", "Samsung", 100M, new Battery(BatteryTypes.LiIon, 310, 8), new Display(4, 16 * 1024)); Call call = new Call("0899798546", 100); gsm.AddCall(call); call = new Call("+35902364972", 50); gsm.AddCall(call); call = new Call("+35905235678", 1000); gsm.AddCall(call); Console.WriteLine("Information about the calls:"); Console.WriteLine(gsm.CallHistoryToString()); Console.WriteLine(); decimal price = gsm.CalculateCallHistoryPrice(0.37M); Console.WriteLine("Calls total price"); Console.WriteLine("{0:F2}", price); Console.WriteLine(); Call longestCall = gsm.CallHistory.OrderByDescending(x => x.Duration).FirstOrDefault(); if (longestCall != null) { gsm.DeleteCall(longestCall); Console.WriteLine("Longest call is removed."); } else { Console.WriteLine("Longest call is not found."); } price = gsm.CalculateCallHistoryPrice(0.37M); Console.WriteLine("Calls total price"); Console.WriteLine("{0:F2}", price); Console.WriteLine(); gsm.ClearCallHistory(); Console.WriteLine("Call history is cleared"); Console.WriteLine("Information about the calls:"); Console.WriteLine(gsm.CallHistoryToString()); }
public void TestCallRate() { GSM phone = new GSM("lala", "sumsAng", "batman", 10000.99); phone.MakeCall(DateTime.Now, "0899999999", 3.44); phone.MakeCall(DateTime.Now, "0899999999", 3.44); phone.MakeCall(DateTime.Now, "0889666999", 9.44); phone.MakeCall(DateTime.Now, "0009666999", 9.44); phone.setCallRate = 0.37; Assert.AreEqual("9.5312", Convert.ToString(phone.CalculateTotalPriceOfCalls())); phone.DeleteCall(3); Assert.AreEqual("6.0384", Convert.ToString(phone.CalculateTotalPriceOfCalls())); phone.ClearCallHistory(); Assert.AreEqual("0", Convert.ToString(phone.CalculateTotalPriceOfCalls())); }
static void Main() { // Initialise an object to the already set static property GSM currentGSM = GSM.IPhone4S; // Add some calls currentGSM.AddCall(DateTime.Now, "12315123", 43); currentGSM.AddCall(DateTime.Now, "123156341", 27); currentGSM.AddCall(DateTime.Now, "080823874", 132); // Get the longest duration call and display details about each call int longestDurationIndex = int.MinValue; int longestDuration = int.MinValue; for (int i = 0; i < currentGSM.CallHistory.Count; i++) { Console.WriteLine(currentGSM.CallHistory[i].ToString()); Console.WriteLine(); if (currentGSM.CallHistory[i].Duration > longestDuration) { longestDurationIndex = i; longestDuration = currentGSM.CallHistory[i].Duration; } } // Calculate total call history price Console.WriteLine("{0:0.00}", currentGSM.CalculateTotalCallPrice(0.37m)); // Remove the longest duration call and recalculate the call history price currentGSM.DeleteCall(longestDurationIndex); Console.WriteLine("{0:0.00}", currentGSM.CalculateTotalCallPrice(0.37m)); // Clear the call history currentGSM.ClearHistory(); foreach (var call in currentGSM.CallHistory) { Console.WriteLine(call.ToString()); } }
static void Main() { GSM testPhone = new GSM("Lumia", "Microsoft"); testPhone.AddCall(new DateTime(2015, 1, 1), 0888123456, 50); testPhone.AddCall(new DateTime(2015, 1, 10), 0888123456, 50); testPhone.AddCall(DateTime.Now, 0888123456, 100); PrintCalls(testPhone.CallHistory); Console.WriteLine("Total price is {0}", testPhone.TotalCallsPrice(0.37)); int longestCallIndex = FindLongestCall(testPhone.CallHistory); testPhone.DeleteCall(longestCallIndex); Console.WriteLine("Total price after removal of longest call is {0}", testPhone.TotalCallsPrice(0.37)); testPhone.ClearCallHistory(); PrintCalls(testPhone.CallHistory); }
static void Main(string[] args) { GSM phone = new GSM("S3", "Samsung", 1000, "Pesho", new Battery("T1", 33, 34, BatteryType.NiCd), new Display()); phone.AddCall(new Call(DateTime.Now, "0521512512", new TimeSpan(1, 30, 20))); phone.AddCall(new Call(DateTime.Now, "0521512512", new TimeSpan(3, 30, 20))); phone.AddCall(new Call(DateTime.Now, "0521512512", new TimeSpan(3, 30, 30))); TimeSpan longestDuration = phone.CallHistory[0].Duration; int index = 0; for (int i = 1; i < phone.CallHistory.Count; i++) { if (longestDuration < phone.CallHistory[i].Duration) { longestDuration = phone.CallHistory[i].Duration; index = i; } } phone.DeleteCall(index); PrintCallHistory(phone); }
static void Main(string[] args) { var gsm = new GSM("M8", "HTC", 100.0m, "Ivan", new Battery { Model = "asdf", HoursIdle = 100 }, new Display()); gsm.CallHistory.Add(new Call() { Duration = 10000000, DialedPhone = "niama takuv nomer" }); for (int i = 0; i < 10; i++) { gsm.AddCall(new Call() { DialedPhone = "000" + i, Duration = (uint)(i + 1) * 120 }); } var maxCall = new Call(); foreach (Call call in gsm.CallHistory) { Console.WriteLine(call); if (maxCall.Duration < call.Duration) { maxCall = call; } } Console.WriteLine(gsm.CalculateTotalCost(0.37m)); gsm.DeleteCall(maxCall); Console.WriteLine(gsm.CalculateTotalCost(0.37m)); // Console.WriteLine(gsm); // Console.WriteLine(GSM.IPhone4S); }
public void GSMCallHistoryTests() { Battery battery = new Battery("BatteryModel", 50, 70, BatteryType.NiMH); Display display = new Display(20, 65000); GSM phone = new GSM("k50in", "Nokia", 999, "Petyrcho", battery, display); //calls DateTime day1 = new DateTime(2013,02,25,12,10,43); Call call1 = new Call(day1, "0888888888", 175); DateTime day2 = new DateTime(2013, 02, 25, 15, 10, 13); Call call2 = new Call(day2, "0888888888", 115); DateTime day3 = new DateTime(2013, 02, 25, 22, 18, 07); Call call3 = new Call(day3, "0888888888", 741); //Display the information about the calls. Console.WriteLine(call1); Console.WriteLine(call2); Console.WriteLine(call3); //Assuming that the price per minute is 0.37 calculate and print the total price of the calls in the history // adding the calls in the call history phone.AddCalls(call1); phone.AddCalls(call2); phone.AddCalls(call3); // calculate the total price Console.Write("Total price : "); Console.WriteLine(phone.TotalPrice(37)); //Remove the longest call from the history and calculate the total price again. Console.Write("The longest call is : "); Console.WriteLine(phone.LongestCall.Duration); //removing the longest call phone.DeleteCall(phone.LongestCall); //total price without the longest call Console.Write("Total price without the longest call is : "); Console.WriteLine(phone.TotalPrice(37)); //Finally clear the call history and print it phone.ClearCallHistory(); //print Console.WriteLine("History : "); Console.WriteLine(" " +phone.CallHistory.Count); //The next will be better }
static void Main() { //GSMTest Display the information about the GSMs in the array. GSM[] myGSMs = new GSM[5]; GSM phone; for (int i = 0; i < myGSMs.Length; i++) { phone = new GSM("model "+i,"manufact"); myGSMs[i]=phone; Console.WriteLine(myGSMs[i].ToString()); } //Display the information about the static property IPhone4S GSM.iPhone4s.ToString(); //Add few calls. phone = new GSM("jhgfhjg540", "manufact"); Random rand = new Random(); int phoneForDelete=0; for (int i = 0; i < 5; i++) { phone.AddCall(DateTime.Now, rand.Next(100000, 9999999).ToString(), rand.Next(1, 250)); if (i==2) { phoneForDelete=rand.Next(100000, 9999999); phone.AddCall(DateTime.Now, phoneForDelete.ToString(), rand.Next(1, 250)); i++; } } //Display the information about the calls. phone.DisplayCallHistory(); //Assuming that the price per minute is 0.37 calculate and print the total price of the calls in the history. Console.WriteLine("Price: "+phone.CalcPrice(0.37)); //Remove the longest call from the history and calculate the total price again. phone.DeleteCall(phoneForDelete.ToString()); phone.DisplayCallHistory(); //Finally clear the call history and print it phone.ClearHistory(); phone.DisplayCallHistory(); }
private static void GSMCallHistoryTest() { GSM testGSM = new GSM("Nokia", "Telerik - A Progress Company"); testGSM.AddCall("+359873432142", 53); testGSM.AddCall("+359811432142", 123); testGSM.AddCall("+359872412142", 41); testGSM.AddCall("+359833332142", 72); testGSM.AddCall("+359614432142", 231); testGSM.ShowCallHistory(); Console.WriteLine("Total call price: " + testGSM.TotalCallPrice()); testGSM.DeleteCall(5); Console.WriteLine("Longest call was removed."); Console.WriteLine("Total call price: " + testGSM.TotalCallPrice()); testGSM.ClearCallHistory(); Console.WriteLine("Call history was removed."); testGSM.ShowCallHistory(); }
private static void GSMCallHistoryTest() { GSM testGSM = new GSM("Nokia", "Telerik - A Progress Company"); testGSM.AddCall("+359873432142", 53); testGSM.AddCall("+359811432142", 123); testGSM.AddCall("+359872412142", 41); testGSM.AddCall("+359833332142", 72); testGSM.AddCall("+359614432142", 231); testGSM.ShowCallHistory(); Console.WriteLine("Total call price: " + testGSM.TotalCallPrice()); testGSM.DeleteCall(5); Console.WriteLine("Longest call was removed."); Console.WriteLine("Total call price: " + testGSM.TotalCallPrice()); testGSM.ClearCallHistory(); Console.WriteLine("Call history was removed."); testGSM.ShowCallHistory(); }
static void Main(string[] args) { GSM gsm = new GSM("HTC One X", "HTC", 799.00, "Vankata", 4.7, 16000000); gsm.AddCall(new Call(DateTime.Parse("12.09.2013 15:00:12"), "+359888333555", 122)); // Price for the call = 1.11 gsm.AddCall(new Call(DateTime.Parse("20.9.2013 17:52:51"), "+359889121223", 54)); // Price for the call = 0.37 gsm.AddCall(new Call(DateTime.Parse("25.09.2013 8:10:22"), "+359789444222", 180)); // Price for the call = 1.11 Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(gsm.CallsInformation()); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Total price of the calls = {0}", gsm.TotalPriceOfCalls(0.37)); // Total price = 2.59 int maxDuration = -1; int indexMaxDuration = -1; for (int i = 0; i < gsm.CallHistory.Count; i++) { if (gsm.CallHistory[i].Duration > maxDuration) { maxDuration = gsm.CallHistory[i].Duration; indexMaxDuration = i; } } gsm.DeleteCall(indexMaxDuration); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("Total price of the calls = {0}", gsm.TotalPriceOfCalls(0.37)); // Total price = 1.48 gsm.ClearHistory(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Total price of the calls = {0}", gsm.TotalPriceOfCalls(0.37)); // Total price = 0 Console.WriteLine(); }
static void Main() { GSM firstGSM = new GSM(); // USER INPUT //Console.WriteLine("Enter phone model: "); //firstGSM.Model = Console.ReadLine(); //Console.WriteLine("Enter manufacturer: "); //firstGSM.Manufacturer = Console.ReadLine(); //Console.WriteLine("Enter price: "); //firstGSM.Price = int.Parse(Console.ReadLine()); //Console.WriteLine("Enter owner: "); //firstGSM.Owner = Console.ReadLine(); //Console.WriteLine("Enter battery model between Li-Ion,NiMH,NiCD(0-2): "); //firstGSM.Battery.Model = (BatteryType)int.Parse(Console.ReadLine()); //Console.WriteLine("Enter hours idle: "); //firstGSM.Battery.HoursIdle = double.Parse(Console.ReadLine()); //Console.WriteLine("Enter hours talked: "); //firstGSM.Battery.HoursTalked = double.Parse(Console.ReadLine()); //Console.WriteLine("Enter display size: "); //firstGSM.Display.Size = uint.Parse(Console.ReadLine()); //Console.WriteLine("Enter display colours: "); //firstGSM.Display.Colours = uint.Parse(Console.ReadLine()); //AUTO INPUT firstGSM.Model = "Galaxy S"; firstGSM.Manufacturer = "Samsung"; firstGSM.Price = 899; firstGSM.Owner = "The Owner"; firstGSM.Battery.Model = BatteryType.NiCD; firstGSM.Battery.HoursIdle = 216.5; firstGSM.Battery.HoursTalked = 15.5; firstGSM.Display.Size = 11; firstGSM.Display.Colours = 65356; firstGSM.Print(); firstGSM.Battery.Print(); firstGSM.Display.Print(); GSM newGSM = new GSM("IPhone", "Apple"); newGSM.Print(); newGSM.Battery.Print(); newGSM.Display.Print(); GSM thirdGSM = new GSM("Phone", "Manufact", 106, "Over"); thirdGSM.Print(); //Create an array of few instances of the GSM class GSM[] myGSM = new GSM[3]; myGSM[0] = new GSM("Galaxy S2", "Samsung", 750, "Nikolai"); myGSM[1] = new GSM("3110", "Nokia", 10, "Nikolai"); myGSM[2] = new GSM("N70", "Nokia", 300, "Nikolai"); //Display the information about the GSMs in the array for (int i = 0; i < myGSM.Length; i++) { myGSM[i].Print(); } Console.WriteLine(); //Display the information about the static property IPhone4S. GSM.IPhone4S.Print(); //Assume the price per minute is fixed and is provided as a parameter. //Assuming that the price per minute is 0.37 double pricePerMin = 0.37; //Create an instance of the GSM class. GSM lastGSM = new GSM("Xperia", "Nokia", 800, "Pesho"); //Add few calls. lastGSM.AddCall("08955454521", 300); lastGSM.AddCall("25665663663", 165); lastGSM.AddCall("252689657954", 214); List <Call> history = lastGSM.CallHistory; //Display the information about the calls. foreach (var call in history) { call.PrintCall(); Console.WriteLine(); } //Calculate and print the total price of the calls in the history. Console.WriteLine("The price for the calls is : {0}", lastGSM.CalcPrice(pricePerMin)); //Select the longest call int maxDurationIndex = 0; uint maxDuration = 0; for (int i = 0; i < history.Count; i++) { if (history[i].Duration > maxDuration) { maxDurationIndex = i; maxDuration = history[i].Duration; } } //Remove the longest call from the history lastGSM.DeleteCall(maxDurationIndex); //Calculate the total price again. Console.WriteLine("The price for the calls is : {0}", lastGSM.CalcPrice(pricePerMin)); //Finally clear the call history lastGSM.ClearHistory(); //and print it. foreach (var call in history) { call.PrintCall(); Console.WriteLine(); } }
static void Main() { GSM firstGSM = new GSM(); // USER INPUT //Console.WriteLine("Enter phone model: "); //firstGSM.Model = Console.ReadLine(); //Console.WriteLine("Enter manufacturer: "); //firstGSM.Manufacturer = Console.ReadLine(); //Console.WriteLine("Enter price: "); //firstGSM.Price = int.Parse(Console.ReadLine()); //Console.WriteLine("Enter owner: "); //firstGSM.Owner = Console.ReadLine(); //Console.WriteLine("Enter battery model between Li-Ion,NiMH,NiCD(0-2): "); //firstGSM.Battery.Model = (BatteryType)int.Parse(Console.ReadLine()); //Console.WriteLine("Enter hours idle: "); //firstGSM.Battery.HoursIdle = double.Parse(Console.ReadLine()); //Console.WriteLine("Enter hours talked: "); //firstGSM.Battery.HoursTalked = double.Parse(Console.ReadLine()); //Console.WriteLine("Enter display size: "); //firstGSM.Display.Size = uint.Parse(Console.ReadLine()); //Console.WriteLine("Enter display colours: "); //firstGSM.Display.Colours = uint.Parse(Console.ReadLine()); //AUTO INPUT firstGSM.Model = "Galaxy S"; firstGSM.Manufacturer = "Samsung"; firstGSM.Price = 899; firstGSM.Owner = "The Owner"; firstGSM.Battery.Model = BatteryType.NiCD; firstGSM.Battery.HoursIdle = 216.5; firstGSM.Battery.HoursTalked = 15.5; firstGSM.Display.Size = 11; firstGSM.Display.Colours = 65356; firstGSM.Print(); firstGSM.Battery.Print(); firstGSM.Display.Print(); GSM newGSM = new GSM("IPhone","Apple"); newGSM.Print(); newGSM.Battery.Print(); newGSM.Display.Print(); GSM thirdGSM = new GSM("Phone", "Manufact", 106, "Over"); thirdGSM.Print(); //Create an array of few instances of the GSM class GSM[] myGSM = new GSM[3]; myGSM[0] = new GSM("Galaxy S2", "Samsung", 750, "Nikolai"); myGSM[1] = new GSM("3110", "Nokia", 10, "Nikolai"); myGSM[2] = new GSM("N70", "Nokia", 300, "Nikolai"); //Display the information about the GSMs in the array for (int i = 0; i < myGSM.Length; i++) { myGSM[i].Print(); } Console.WriteLine(); //Display the information about the static property IPhone4S. GSM.IPhone4S.Print(); //Assume the price per minute is fixed and is provided as a parameter. //Assuming that the price per minute is 0.37 double pricePerMin = 0.37; //Create an instance of the GSM class. GSM lastGSM = new GSM("Xperia", "Nokia", 800, "Pesho"); //Add few calls. lastGSM.AddCall("08955454521", 300); lastGSM.AddCall("25665663663", 165); lastGSM.AddCall("252689657954", 214); List<Call> history = lastGSM.CallHistory; //Display the information about the calls. foreach (var call in history) { call.PrintCall(); Console.WriteLine(); } //Calculate and print the total price of the calls in the history. Console.WriteLine("The price for the calls is : {0}", lastGSM.CalcPrice(pricePerMin)); //Select the longest call int maxDurationIndex = 0; uint maxDuration = 0; for (int i = 0; i < history.Count; i++) { if (history[i].Duration > maxDuration) { maxDurationIndex = i; maxDuration = history[i].Duration; } } //Remove the longest call from the history lastGSM.DeleteCall(maxDurationIndex); //Calculate the total price again. Console.WriteLine("The price for the calls is : {0}", lastGSM.CalcPrice(pricePerMin)); //Finally clear the call history lastGSM.ClearHistory(); //and print it. foreach (var call in history) { call.PrintCall(); Console.WriteLine(); } }
public static void Main() { Console.OutputEncoding = System.Text.Encoding.Unicode; //for the price to be displayed correctly we set bulgarian culture Thread.CurrentThread.CurrentCulture = new CultureInfo("bg-BG"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("bg-BG"); var battery = new Battery("MegaBattery", 48, 10, BatteryType.LiIon); var display = new Display(15.6, 99999999); var prestigio = new GSM("PAP4055DUO", "Prestigio", 150, "Boco", battery, display); var phoneWithMinSpecs = new GSM("someModel", "someManufacturer"); var basicPhone = new GSM("Nokia", "TANK", 20, "Grandpa"); var iphone = GSM.IPhone4S; iphone.Owner = "NotMe"; GSM[] listOfPhones = new GSM[] { prestigio, phoneWithMinSpecs, basicPhone, iphone }; for (int phone = 0; phone < listOfPhones.Length; phone++) { Console.WriteLine(new string('-', 70)); Console.WriteLine(listOfPhones[phone].ToString()); Console.WriteLine(new string('-', 70)); } Console.WriteLine("Static property iPhone4S: \n{0}", GSM.IPhone4S); //LAST TASK (I use the already created phone prestigio) //add a few calls prestigio.AddCall(DateTime.Now, new TimeSpan(0, 0, 2, 12), "08827102xx"); prestigio.AddCall(new DateTime(2014, 12, 23, 12, 22, 31), new TimeSpan(0, 0, 1, 30), "08827103xx"); prestigio.AddCall(new DateTime(2014, 12, 22, 21, 22, 31), new TimeSpan(0, 0, 4, 12), "08827104xx"); //Display info about the calls in the call history foreach (var call in prestigio.CallHistory) { Console.WriteLine("Call: Date&Time: {0}, Duration: {1}, dialedPhoneNumber: {2}", call.Date, call.Duration, call.DialedPhoneNumber); } //Calculate the total price of all calls Console.WriteLine("Total price in all call in history: {0}", prestigio.CalculateTotalCallCost(0.37m)); TimeSpan crntMaxDuration = new TimeSpan(0, 0, 0, 0); int maxIndex = -1; for (var call = 0; call < prestigio.CallHistory.Count; call++) { if (prestigio.CallHistory[call].Duration > crntMaxDuration) { crntMaxDuration = prestigio.CallHistory[call].Duration; maxIndex = call; } } prestigio.DeleteCall(prestigio.CallHistory[maxIndex].Date); //remove by date, because only 1 call has this date, its unique like an ID //Display calls after deletion Console.WriteLine("After the longest call has been deleted, calls are: \n{0}\n", new string('-', 70)); foreach (var call in prestigio.CallHistory) { Console.WriteLine("Call: Date&Time: {0}, Duration: {1}, dialedPhoneNumber: {2}", call.Date, call.Duration, call.DialedPhoneNumber); } prestigio.DeleteCallHistory(); Console.WriteLine("After callHistory has been cleared, all calls are: "); foreach (var call in prestigio.CallHistory) { Console.WriteLine("Call: Date&Time: {0}, Duration: {1}, dialedPhoneNumber: {2}", call.Date, call.Duration, call.DialedPhoneNumber); } }
static void Main() { GSM[] gsmArray = { new GSM("S3", "Galaxy", 710M, "Reni", new Battery("A12", 20, 5, BatteryType.LiIon), new Display(4.8, 50000)), new GSM("5", "Nexus", 610M, "Stasko", new Battery("A13", 19, 6, BatteryType.NiCd), new Display(5, 40000)), }; foreach (var gsm in gsmArray) { Console.WriteLine(gsm.ToString()); Console.WriteLine(new string('-', 50)); } Console.WriteLine("Static property: {0}", GSM.IPhone4S); GSM myGSM = new GSM("Xperia", "Sony", 510M, "Didi", new Battery("A14", 15, 7, BatteryType.NiMH), new Display(4.9, 45000)); List<Call> callHistory = new List<Call> { new Call(new DateTime(2015, 03, 18), new Time(23, 22, 56), "0888123456", 360), new Call(new DateTime(2015, 02, 19), new Time(13, 19, 25), "0888124556", 520), new Call(new DateTime(2015, 01, 15), new Time(11, 10, 20), "0888124106", 800) }; //add calls to call history list foreach (var call in callHistory) { myGSM.AddCall(call); } Console.WriteLine(myGSM.ToString()); myGSM.CallHistory.Add(new Call(new DateTime(2015, 01, 15), new Time(11, 10, 20), "0888124106", 800)); //print call history myGSM.PrintCallHistory(); //calculate total price and print it decimal totalPrice = myGSM.CallPrice(myGSM.CallHistory, 0.37M); Console.WriteLine("Total call's price: {0}", totalPrice); //remove the longest call from the history Call longestCall = new Call(); foreach (var call in callHistory) { if (longestCall.Duration <= call.Duration) { longestCall = call; } } //delete longest call myGSM.DeleteCall(longestCall); myGSM.PrintCallHistory(); //calculate the total price again totalPrice = myGSM.CallPrice(myGSM.CallHistory, 0.37M); Console.WriteLine("Total call's price: {0}", totalPrice); //clear the call history and print it. myGSM.ClearHistory(); myGSM.PrintCallHistory(); }
static void Main() { GSM[] gsmArray = { new GSM("S3", "Galaxy", 710M, "Reni", new Battery("A12", 20, 5, BatteryType.LiIon), new Display(4.8, 50000)), new GSM("5", "Nexus", 610M, "Stasko", new Battery("A13", 19, 6, BatteryType.NiCd), new Display(5, 40000)), }; foreach (var gsm in gsmArray) { Console.WriteLine(gsm.ToString()); Console.WriteLine(new string('-', 50)); } Console.WriteLine("Static property: {0}", GSM.IPhone4S); GSM myGSM = new GSM("Xperia", "Sony", 510M, "Didi", new Battery("A14", 15, 7, BatteryType.NiMH), new Display(4.9, 45000)); List <Call> callHistory = new List <Call> { new Call(new DateTime(2015, 03, 18), new Time(23, 22, 56), "0888123456", 360), new Call(new DateTime(2015, 02, 19), new Time(13, 19, 25), "0888124556", 520), new Call(new DateTime(2015, 01, 15), new Time(11, 10, 20), "0888124106", 800) }; //add calls to call history list foreach (var call in callHistory) { myGSM.AddCall(call); } Console.WriteLine(myGSM.ToString()); myGSM.CallHistory.Add(new Call(new DateTime(2015, 01, 15), new Time(11, 10, 20), "0888124106", 800)); //print call history myGSM.PrintCallHistory(); //calculate total price and print it decimal totalPrice = myGSM.CallPrice(myGSM.CallHistory, 0.37M); Console.WriteLine("Total call's price: {0}", totalPrice); //remove the longest call from the history Call longestCall = new Call(); foreach (var call in callHistory) { if (longestCall.Duration <= call.Duration) { longestCall = call; } } //delete longest call myGSM.DeleteCall(longestCall); myGSM.PrintCallHistory(); //calculate the total price again totalPrice = myGSM.CallPrice(myGSM.CallHistory, 0.37M); Console.WriteLine("Total call's price: {0}", totalPrice); //clear the call history and print it. myGSM.ClearHistory(); myGSM.PrintCallHistory(); }