static void Main() { DateTime date1 = new DateTime(2013, 5, 24, 11, 11, 30); DateTime date2 = new DateTime(2013, 5, 24, 15, 23, 2); DateTime date3 = new DateTime(2013, 5, 31, 9, 00, 00); DateTime date4 = new DateTime(2013, 5, 31, 18, 12, 20); Call call1 = new Call(date1, "0888313233", 850); Call call2 = new Call(date2, "0888909090", 95); Call call3 = new Call(date3, "0889556677", 213); Call call4 = new Call(date4, "0888313233", 37); Battery battery = new Battery("PX8", BatteryType.LiIon, 300, 8); Display display = new Display(4, 16000000); GSM gsm = new GSM("I900", "Samsung", 500, "Me", battery, display); gsm.AddCalls(call1); gsm.AddCalls(call2); gsm.AddCalls(call3); gsm.AddCalls(call4); foreach (var call in gsm.CallHistory) { Console.WriteLine(call); } Console.WriteLine("Total amount to pay: {0:C}", gsm.TotalCallsPrice); gsm.DeleteCalls(call1); Console.WriteLine("Total amount to pay: {0:C}", gsm.TotalCallsPrice); gsm.ClearHistory(); Console.WriteLine("Total amount to pay: {0:C}", gsm.TotalCallsPrice); }
//test the call history functionality static void Main() { //Create a new mobile phone GSM mobile = new GSM("Xperia", "Sony", 670.99, "Kitty"); //Get information about created mobile phone mobile.ToString(); //Get information about static field iPhone GSM.IPhone4S.ToString(); //Add calls and print mobile.AddCalls(DateTime.Now, "+359 885 440 340", 1); mobile.AddCalls(DateTime.Now, "+359 886 789 451", 94); mobile.PrintCalls(); //Delete call and print mobile.DeleteCalls(2); mobile.PrintCalls(); //Calculate total price mobile.CalculateFinalPrice(0.35); //Clear calls and print mobile.ClearCalls(); }
static void Main() { DateTime date1 = new DateTime(2013, 5, 24, 11, 11, 30); DateTime date2 = new DateTime(2013, 5, 24, 15, 23, 2); DateTime date3 = new DateTime(2013, 5, 31, 9, 00, 00); DateTime date4 = new DateTime(2013, 5, 31, 18, 12, 20); Call call1 = new Call(date1, "0888313233", 850); Call call2 = new Call(date2, "0888909090", 95); Call call3 = new Call(date3, "0889556677", 213); Call call4 = new Call(date4, "0888313233", 37); Battery battery = new Battery ("PX8", BatteryType.LiIon, 300, 8); Display display = new Display(4, 16000000); GSM gsm = new GSM("I900", "Samsung", 500, "Me", battery, display); gsm.AddCalls(call1); gsm.AddCalls(call2); gsm.AddCalls(call3); gsm.AddCalls(call4); foreach (var call in gsm.CallHistory) { Console.WriteLine(call); } Console.WriteLine("Total amount to pay: {0:C}",gsm.TotalCallsPrice); gsm.DeleteCalls(call1); Console.WriteLine("Total amount to pay: {0:C}", gsm.TotalCallsPrice); gsm.ClearHistory(); Console.WriteLine("Total amount to pay: {0:C}", gsm.TotalCallsPrice); }
static void Main(string[] args) { //Problem 12. Call history test //12.1 Create an instance of the GSM class. GSM s8 = new GSM("Galaxy S8 Plus", "Samsung", "600$", owner: "Ben", batterySpec: new Battery { BatteryModel = "Samsung 3500mAh battery", HoursIdle = 96, HoursTalk = 27, BatteryType = BatteryType.LiIon }, displaySpec: new Display()); //12.2 Add few calls. int countOfCalls = 7; Call[] allCalls = new Call[countOfCalls]; int clientPhoneNumber = 889977550; //set calls and their duration time// for (int index = 0; index < countOfCalls; index++) { clientPhoneNumber = clientPhoneNumber + index; //simple random number adding allCalls[index] = new Call(); allCalls[index].DialedPhoneNumber = "0" + clientPhoneNumber; allCalls[index].Duration = 10 + index * 2; //duration is in seconds (start from 10 seconds for first call and increase for the next one) } s8.AddCalls(allCalls); //12.3 Display the information about the calls. Console.WriteLine(s8.CallHistoryToString()); //12.4 Calculate and print the total price of the calls in the history. (the price per minute is 0.37$) Console.WriteLine("Total price of calls: " + s8.CalculateTotalPrice(pricePerMinute: 0.37m) + "$"); //12.5 Remove the longest call from the history and calculate the total price again. //manually set duration time for testing purpose// allCalls[0].Duration = 480; //set first call(889977550) to 8 min (this call duration, should be the longest one) //order by duration time (with lambda expression) var orderedCall = allCalls.OrderBy(x => x.Duration); var longestCall = orderedCall.Last(); allCalls = orderedCall.ToArray(); //add new ordered call history and delete the longest one s8.ClearCallHistory(); s8.AddCalls(allCalls); s8.DeleteCalls(longestCall.DialedPhoneNumber); //calculate the total price Console.WriteLine("Total price of calls: " + s8.CalculateTotalPrice() + "$ (new calculation)"); //12.6 Finally clear the call history s8.ClearCallHistory(); }
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()); } }
static void Main() { GSM testPhone = new GSM("L6", "Motorola"); testPhone.AddCalls(DateTime.Now, "0879454532", 62); testPhone.AddCalls(DateTime.Now, "8787878789", 500); testPhone.AddCalls(DateTime.Now, "4545454545", 420); testPhone.AddCalls(DateTime.Now, "1111111111", 100); testPhone.DisplayCallInformation(); double finalPrice = testPhone.CalculatePrice(0.37); Console.WriteLine("This is the price for all the calls"); Console.WriteLine(finalPrice); testPhone.DeleteCalls(500); double priceAfterRemoval = testPhone.CalculatePrice(0.37); Console.WriteLine("This is the price without the longest call:"); Console.WriteLine(priceAfterRemoval); testPhone.ClearingHistory(); testPhone.DisplayCallInformation(); }
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 }
public static void Main() { //Console.Write("Enter number of phones: "); //int number = int.Parse(Console.ReadLine()); //GSM[] phones = new GSM[number]; //for (int i = 0; i < number; i++) //{ // Console.Write("Enter phone model: "); // string model = Console.ReadLine(); // Console.Write("Enter phone manifacutrer: "); // string manifacture = Console.ReadLine(); // Console.Write("Enter phone owner: "); // string owner = Console.ReadLine(); // Console.Write("Enter phone price: "); // string price = Console.ReadLine(); // Console.Write("Enter phone batter model: "); // string batteryModel = Console.ReadLine(); // Console.Write("Enter phone battery idle hours: "); // string idleHours = Console.ReadLine(); // Console.Write("Enter phone battery talk hours: "); // string talkHours = Console.ReadLine(); // Console.Write("Enter phone display size: "); // string displaySize = Console.ReadLine(); // Console.Write("Enter phone number of colors: "); // string displayColors = Console.ReadLine(); // phones[i] = new GSM(model, manifacture, owner, double.Parse(price), batteryModel, int.Parse(idleHours), int.Parse(talkHours), double.Parse(displaySize), int.Parse(displayColors)); //} //foreach (var item in phones) //{ // Console.WriteLine(); // item.GetInfo(); //Console.WriteLine(item.ToString()); // Console.WriteLine(); //} //---------------------------------------------------------------------------------------------------// //CallHistoryTest GSM mobile = new GSM("3310", "Nokia", "Some swedish guy", 100m, "ARhd34", 310, 140, 4.3f, 16000000, BatteryType.LiIon); Console.WriteLine(mobile.ToString()); //mobile.GetInfo(); mobile.AddCalls("12:50", 0894216738, 50, 21, 12, 2013); mobile.AddCalls("16:23", 0894216738, 120, 21, 12, 2013); mobile.AddCalls("18:32", 0894216738, 23, 24, 12, 2013); mobile.AddCalls("12:17", 0894216738, 180, 29, 12, 2013); //Get info for the calls Console.WriteLine(); foreach (var item in mobile.callHistory) { Console.WriteLine(item.date + " " + item.dialedNumber + " " + item.duration + " " + item.Time); } //Print total price Console.WriteLine(); Console.WriteLine("Total price: {0}", mobile.CalculateTotalBill(0.37m)); //Delete longest call and print price again mobile.callHistory.Remove(mobile.callHistory[3]); Console.WriteLine(); Console.WriteLine("Total price: {0}", mobile.CalculateTotalBill(0.37m)); //Clear call history and print again mobile.callHistory.Clear(); Console.WriteLine(); foreach (var item in mobile.callHistory) { Console.WriteLine(item.date + " " + item.dialedNumber + " " + item.duration + " " + item.Time); } }