private static void CreateUserInterface() { Console.WriteLine("Enter the number of the menu you want to choose :"); Console.WriteLine("1. TestGSM"); Console.WriteLine("2. Perform a Call"); Console.WriteLine("3. Check Call History"); Console.WriteLine("4. Calculate price of all calls"); Console.WriteLine("5. Do a Call HIstory Test"); int result = int.Parse(Console.ReadLine()); switch (result) { case 1: Console.WriteLine("How many GSMs to create?"); int res = int.Parse(Console.ReadLine()); Console.WriteLine("Enter the IphoneInfo"); string iphoneRes = Console.ReadLine(); GSMTestMethod(res, iphoneRes); GetBackToMainMenu(); break; case 2: Console.WriteLine("Enter the mobile number you want to dial"); string number = Console.ReadLine(); newCall = new Call(number); Console.WriteLine("The number {0} is being dialed press enter when you want to hang up",number); Console.ReadLine(); newCall.HangUp(); newGSm.callHistory.Add(newCall); Console.WriteLine("The call lasted {0} seconds",newCall.duration); GetBackToMainMenu(); break; case 3: foreach (var call in newGSm.callHistory) { Console.WriteLine(call.ToString()); } GetBackToMainMenu(); break; case 4: double rndPrice = 0.59; string totalPrice = newGSm.CalculatePrice(rndPrice); Console.WriteLine("Your price for all calls is {0}",totalPrice); break; case 5: CallHIstoryTest.doTests(); break; default: break; } }
public static void doTests() { GSM newGSm = new GSM(Models.Iphone, "Dunno"); Console.WriteLine("Phone Created"); Console.WriteLine("Please wait while generating calls..."); int rndCallsAmount = rnd.Next(2,10); for (int i = 0; i < rndCallsAmount ; i++) { string number = (rnd.Next(500000, 700000)).ToString(); Call newCall = new Call(number); int rndThreadSleep = rnd.Next(1000,6000); Thread.Sleep(rndThreadSleep); newCall.HangUp(); newGSm.callHistory.Add(newCall); } Console.WriteLine("Calls generated"); Console.WriteLine("Writing info"); foreach (var call in newGSm.callHistory) { Console.WriteLine(call); } Console.WriteLine(); Console.WriteLine("Calculating price for 0.37 per minute"); string price = newGSm.CalculatePrice(0.37); Console.WriteLine("Price is {0}",price); Console.WriteLine("Findign and removing the longest call"); double longestCall = 0; int index = 0; for (int i = 0; i < newGSm.callHistory.Count; i++) { if (double.Parse(newGSm.callHistory[i].duration) > longestCall) { longestCall = double.Parse(newGSm.callHistory[i].duration); index = i; } } newGSm.callHistory.RemoveAt(index); Console.WriteLine("Recalculating price"); price = newGSm.CalculatePrice(0.37); Console.WriteLine("Price is {0}", price); newGSm.callHistory.Clear(); Console.WriteLine("History Cleared"); }