Exemplo n.º 1
0
        public static void CallHistoryTest()
        {
            //Create an instance of the GSM class.
            GSM myGsm = GSM.IPhone4S;

            //Add few calls.
            Call someCall = new Call(DateTime.Now, 120, "+359888888888");
            myGsm.AddCall(someCall);
            myGsm.AddCall(someCall);
            myGsm.DeleteCall(someCall);
            myGsm.AddCall(someCall);
            myGsm.AddCall(new Call(new DateTime(2013, 2, 10, 21, 14, 29), 1000, "0885088508"));
            myGsm.AddCall(new Call(new DateTime(2013, 1, 20, 11, 11, 11), 1000, "0885088508"));
            myGsm.AddCall(new Call(DateTime.Now, 119, "+359887121314"));

            //Display the information about the calls.
            Console.WriteLine("All calls:");
            myGsm.PrintAllCalls();

            //Assuming that the price per minute is 0.37 calculate and print the total price of the calls in the history.
            PrintCallPrice(myGsm);

            //Remove the longest call from the historyand calculate the total price again.
            myGsm.RemoveLongestDurationCall();
            Console.WriteLine("\nAfter remove of longest duration call...");
            PrintCallPrice(myGsm);

            //Finally clear the call history and print it.
            myGsm.ClearCallHistory();
            Console.WriteLine("\nAfter clear...");
            myGsm.PrintAllCalls();
            PrintCallPrice(myGsm);
        }
Exemplo n.º 2
0
        static public void AddCall()
        {

            Call thisCall = new Call();
            string anotherCall = null;
            Console.WriteLine();
            Console.WriteLine("You're in mode: Add Call");
            Console.WriteLine();
            Console.Write("Enter Date of the call:");
            thisCall.Date = Console.ReadLine();
            Console.Write("Enter the time when the call was made:");
            thisCall.Time = Console.ReadLine();
            Console.Write("Enter Phone number of the call reciver:");
            thisCall.DialedNumber = Console.ReadLine();
            Console.Write("Enter duration of the call(in seconds):");
            thisCall.Duration = int.Parse(Console.ReadLine());
            if (max < thisCall.Duration)
            {
                max = thisCall.Duration;
                indexOfLongestCall++;  //use this index to dell the longest call later in the 'RemoveCall' method

            }
            thisCall = new Call(thisCall.Date, thisCall.Time, thisCall.DialedNumber, thisCall.Duration);//invoke full argument constructor of class 'Call'
            CallHistory.Add(thisCall);//add the call in List<Call>
            Console.WriteLine();
            Console.Write("Add another call? Type 'yes' to proceed('no' for exit): ");
            anotherCall = Console.ReadLine().ToLower();
            if (anotherCall.Equals("yes"))
            {
                //Bill();
                GSM.AddCall();
            }

        }
Exemplo n.º 3
0
        public static void AddCalls(GSM gsm)
        {
            Call[] callArray = new Call[3];
            callArray[0] = new Call(DateTime.Now, "0889123456", 5);
            callArray[1] = new Call(DateTime.Now, "0889123455", 12);
            callArray[2] = new Call(DateTime.Now, "0878536897", 3);

            for (int index = 0; index < callArray.Length; index++)
            {
                gsm.AddCall(callArray[index]);
            }
        }
Exemplo n.º 4
0
        public static void RemoveLongestCall()
        {
            Call longestCall = new Call(DateTime.Now, "0", 0);

            for (int i = 0; i < testCalls.Length; i++)
            {
                if (testCalls[i].Duration >= longestCall.Duration)
                {
                    longestCall = testCalls[i];
                }
            }

            testGSM.DeleteCalls(longestCall);
        }
        static void Main(string[] args)
        {
            //zad.7
            GSMTest.PrintInfo();

            //Create an instance of the GSM class.
            GSM myPhone = new GSM("N95", "Nokia");

            //Add few calls.
            Call call = new Call(DateTime.Now, "0883333333", 60);
            Call nextCall = new Call(new DateTime(2013,02,10,20,34,20), "+3592376541212", 120);
            myPhone.AddCall(call);
            myPhone.AddCall(nextCall);

            //Display the information about the calls.
            foreach (var c in myPhone.CallHistory)
            {
                Console.WriteLine(c);
            }

            //Assuming that the price per minute is 0.37 calculate and print the total price of the calls in the history.
            Console.Write("The total price of the calls is: ");
            myPhone.PriceOfCalls(0.37m);

            //Remove the longest call from the history and calculate the total price again.
            Call longest = new Call();
            longest.Duration = 0;
            for (int i = 0; i < myPhone.CallHistory.Count; i++)
            {
                if (myPhone.CallHistory[i].Duration > longest.Duration)
                {
                    longest = myPhone.CallHistory[i];
                }
            }
            myPhone.RemoveCall(longest);
            Console.Write("The new price after removing longest call is: ");
            myPhone.PriceOfCalls(0.37m);

            //Finally clear the call history and print it.
            myPhone.ClearCallHistory();
            foreach (var c in myPhone.CallHistory)
            {
                Console.WriteLine(c);
            }
        }
        public void Test()
        {
            GSM iPhone = GSM.IPhone4S;

            //Add Calls
            Call newCaller = new Call("10.02.2012", "17:00", "0886254882", 600);
            Call newCaller2 = new Call("11.12.2012", "17:00", "0886254882", 2500);
            Call newCaller3 = new Call("08.08.2012", "18:00", "0886254882", 600);
            iPhone.AddCall(newCaller);
            iPhone.AddCall(newCaller2);
            iPhone.AddCall(newCaller3);

            //Print CallHistory
            StringBuilder testOutput = new StringBuilder();
            foreach (var call in iPhone.CallHistory)
            {
                string callStr = call.ToString();
                testOutput.Append(callStr);
                testOutput.Append("\n\r");
            }
            Console.WriteLine(testOutput.ToString());

            //Calculate Price
            decimal price = iPhone.CalculatePrice(0.37m);
            Console.WriteLine("{0:F2}лв.", price);

            //Remove one Call from CallHistory
            iPhone.RemoveCall(1);
            testOutput.Remove(0, testOutput.Length);
            foreach (var call in iPhone.CallHistory)
            {
                string callStr = call.ToString();
                testOutput.Append(callStr);
                testOutput.Append("\n\r");
            }
            Console.WriteLine(testOutput.ToString());

            //Calculate New Price
            price = iPhone.CalculatePrice(0.37m);
            Console.WriteLine("{0:F2}лв.", price);

            //Clear CallHistory
            iPhone.EmptyCallHistory();
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            var ipPhone6 = new GSM(model: "IP-Phone6", manufacturer: "xApple");
            var salamSumng = new GSM(model: "Jalacxy7", manufacturer: "SalamSung");

            var listFromSmartPhones = new List<GSM>();
            listFromSmartPhones.Add(ipPhone6);
            listFromSmartPhones.Add(salamSumng);

            foreach (var phones in listFromSmartPhones)
            {
                Console.WriteLine(phones);
            }

            var iPhone4s = GSM.IPhone4s;


            var firstTestCall = new Call()
            {
                TimeStart = DateTime.Now,
                TimeEnd = DateTime.Now.AddMinutes(2),
                ItsIncomming = false,
                PhoneNumber = "0043123123"
            };

            var duration = firstTestCall.Duration();

            var secondTestCall = new Call()
            {
                TimeStart = DateTime.Now,
                TimeEnd = DateTime.Now.AddMinutes(3),
                ItsIncomming = false,
                PhoneNumber = "0043123123"
            };

            ipPhone6.AddCall(firstTestCall);
            ipPhone6.AddCall(secondTestCall);

            decimal pricePerMinute = 0.37M;
            var totalPrice = ipPhone6.CallPrice(pricePerMinute);

            Console.WriteLine("Total call price: " + totalPrice);
        }
Exemplo n.º 8
0
        public void AddCall()
        {
            Call addCall = new Call();

            this.callHistory.Add(addCall);
        }
Exemplo n.º 9
0
 public void AddCall(Call call)
 {
     List<Call> tempCallHistory = new List<Call>(this.CallHistory);
     tempCallHistory.Add(call);
     this.CallHistory = tempCallHistory;
 }
Exemplo n.º 10
0
 public void ClearCallHistory(Call call)
 {
     this.calls.Clear();
 }
Exemplo n.º 11
0
 public void RemoveCall(Call call)
 {
     for (int i = 0; i < callHistory.Count; i++)
     {
         if (call.Duration == callHistory[i].Duration)
         {
             callHistory.RemoveAt(i);
         }
     }
 }
Exemplo n.º 12
0
 //Add CallHistory
 public void AddCall(Call newCall)
 {
     if (callHistory == null)
     {
         callHistory = new List<Call>();
         callHistory.Add(newCall);
     }
     else
     {
         callHistory.Add(newCall);
     }
 }
Exemplo n.º 13
0
 public int DeleteCallFromHistory(Call call)
 {
     if (call == null)
     {
         throw new ArgumentNullException(@"Trying to delete ""null"" call.");
     }
     for (int i = 0; i < callHistory.Count; i++)
     {
         if (callHistory[i].Date == call.Date &&
             callHistory[i].Time == call.Time &&
             callHistory[i].DailedPhone == call.DailedPhone)
         {
             callHistory.RemoveAt(i);
             return 1;
         }
     }
     return -1;
 }
Exemplo n.º 14
0
 public Call DelleteCall(Call call)
 {
     this.callHistory.Remove(call);
     return call;
 }
Exemplo n.º 15
0
        /// <summary>
        /// Closes a call - ends the last opened call from the call list.
        /// </summary>
        public void CloseCall(int durationSeconds = -1)
        {
            if (this.currentCall == null)
            {
                throw new ApplicationException("No call to close!");
            }

            if (durationSeconds < 0)
            {
                this.currentCall.EndCall(); // Will calculate the duration by the system clock
            }
            else
            {
                this.currentCall.EndCall(durationSeconds);
            }

            Call newCall = new Call(this.currentCall); // Copy the current call
            this.callHistory.Add(newCall); // ... and add it to the call history
            this.currentCall = null; // ... release the current call
        }
Exemplo n.º 16
0
 public void RemoveCall(Call call)
 {
     this.CallHistory.Remove(call);
 }
Exemplo n.º 17
0
 public void Remove(Call call)
 {
     this.performedCalls.Remove(call);
 }
Exemplo n.º 18
0
 public void Add(Call call)
 {
     performedCalls.Add(call);
 }
Exemplo n.º 19
0
 public void AddCall(Call newCall)
 {
     this.CallHistory.Add(newCall);
 }
Exemplo n.º 20
0
 public void AddCall(Call call)
 {
     this.CallHistoryAdder = call;
 }
Exemplo n.º 21
0
 public Call AddCall(Call call)
 {
     this.callHistory.Add(call);
     return call;
 }
Exemplo n.º 22
0
 public void AddCallToHistory(int year, int month, int day, int hour, int minute, string dialledNumber, int duration)
 {
     DateTime date = new DateTime(year, month, day, hour, minute, 0);
     Call call = new Call(date, dialledNumber, duration);
     this.callHistory.Add(call);
 }
Exemplo n.º 23
0
        /// <summary>
        /// Opens a new call - creates a new Call object with the dialed number and adds it to the call list.
        /// </summary>
        /// <param name="phoneNum">The dialed number</param>
        public void OpenCall(string phoneNum)
        {
            if (this.currentCall != null)
            {
                throw new ApplicationException("You can't open a new call before you close the old one!");
            }

            this.currentCall = new Call(phoneNum);
        }
Exemplo n.º 24
0
 public void Add(Call call)
 {
     performedCalls.Add(call);
 }
Exemplo n.º 25
0
 // Methods
 public void AddCalls(Call call)
 {
     this.HistoryCall.Add(call);
 }
Exemplo n.º 26
0
 public void Remove(Call call)
 {
     this.performedCalls.Remove(call);
 }
Exemplo n.º 27
0
 public void AddCalltoHistory(Call newCall)
 {
     if (newCall == null)
     {
         throw new ArgumentNullException(@"""null"" calls are not allowed!");
     }
     this.callHistory.Add(newCall);
 }
Exemplo n.º 28
0
 public void AddCall()
 {
     Call addCall = new Call();
     this.callHistory.Add(addCall);
 }
Exemplo n.º 29
0
 public void AddCall(Call call)
 {
     this.calls.Add(call);
 }
Exemplo n.º 30
0
 public void DeleteCall(Call call)
 {
     int index = callHistory.IndexOf(call);
     if (index != -1)
     {
         callHistory.RemoveAt(index);
     }
 }
Exemplo n.º 31
0
 public void DeleteCall(Call call)
 {
     this.calls.Remove(call);
 }
Exemplo n.º 32
0
 public void DeleteCalls(Call data)
 {
     callHistory.Remove(data);
 }
Exemplo n.º 33
0
 public void DeleteCall(Call call)
 {
     this.callHistory.Remove(call);
 }
Exemplo n.º 34
0
 //=== Problem 10 ==> Add methods in the `GSM` class for adding and deleting calls from the calls history. Add a method to clear the call history.
 public void AddCall(Call call)
 {
     CallHistory.Add(call);
 }
Exemplo n.º 35
0
 public void AddCall(Call call)
 {
     this.callHistory.Add(call);
 }
Exemplo n.º 36
0
 public void AddCalls(Call data)
 {
     callHistory.Add(data);
 }