Exemple #1
0
        public static void GSMTest()
        {
            GSM testGSM = new GSM("Alcatel", "Volvo");

            testGSM.AddAndRemove("add", testGSM);
            Console.WriteLine(testGSM.ResentCall.Duration.ToString());
            Console.WriteLine(testGSM.ResentCall.LastNumber);

            testGSM.AddAndRemove("add", testGSM);
            Console.WriteLine(testGSM.ResentCall.Duration.ToString());
            Console.WriteLine(testGSM.ResentCall.LastNumber);

            testGSM.AddAndRemove("add", testGSM);
            Console.WriteLine(testGSM.ResentCall.Duration.ToString());
            Console.WriteLine(testGSM.ResentCall.LastNumber);

            double totalPrice = testGSM.TotalPriceOfCalls(testGSM);

            Console.WriteLine(totalPrice);

            int longestTalkIndex = 0;

            for (int i = 1; i < testGSM.CallHistory.Count; i++)
            {
                if (testGSM.CallHistory[i - 1].Duration > testGSM.CallHistory[i].Duration)
                {
                    {
                        longestTalkIndex = i - 1;
                    }
                }

                if (i == testGSM.CallHistory.Count - 1 && testGSM.CallHistory[i - 1].Duration < testGSM.CallHistory[i].Duration)
                {
                    longestTalkIndex = i;
                }
            }

            testGSM.CallHistory.RemoveAt(longestTalkIndex);
            double newTotalPrice = testGSM.TotalPriceOfCalls(testGSM);

            Console.WriteLine(newTotalPrice);
            for (int i = 0; i < testGSM.CallHistory.Count; i++)
            {
                Console.WriteLine(testGSM.CallHistory[i].LastNumber);
                testGSM.CallHistory.RemoveAt(i);
            }
        }
        public static void GSMTest()
        {
            GSM testGSM = new GSM("Alcatel", "Volvo");

            testGSM.AddAndRemove("add", testGSM);
            Console.WriteLine(testGSM.ResentCall.Duration.ToString());
            Console.WriteLine(testGSM.ResentCall.LastNumber);

            testGSM.AddAndRemove("add", testGSM);
            Console.WriteLine(testGSM.ResentCall.Duration.ToString());
            Console.WriteLine(testGSM.ResentCall.LastNumber);

            testGSM.AddAndRemove("add", testGSM);
            Console.WriteLine(testGSM.ResentCall.Duration.ToString());
            Console.WriteLine(testGSM.ResentCall.LastNumber);

            double totalPrice = testGSM.TotalPriceOfCalls(testGSM);
            Console.WriteLine(totalPrice);

            int longestTalkIndex = 0;
            for (int i = 1; i < testGSM.CallHistory.Count; i++)
            {
                if (testGSM.CallHistory[i - 1].Duration > testGSM.CallHistory[i].Duration)
                {
                    {
                        longestTalkIndex = i - 1;
                    }
                }

                if (i == testGSM.CallHistory.Count - 1 && testGSM.CallHistory[i - 1].Duration < testGSM.CallHistory[i].Duration)
                {
                    longestTalkIndex = i;
                }
            }

            testGSM.CallHistory.RemoveAt(longestTalkIndex);
            double newTotalPrice = testGSM.TotalPriceOfCalls(testGSM);
            Console.WriteLine(newTotalPrice);
            for (int i = 0; i < testGSM.CallHistory.Count; i++)
            {
                Console.WriteLine(testGSM.CallHistory[i].LastNumber);
                testGSM.CallHistory.RemoveAt(i);
            }
        }
Exemple #3
0
        private static void Main()
        {
            // Inserting data:
            GSM myPhone = new GSM("Nokia", "Nokia OOD");
            myPhone.Price = 500;
            myPhone.Owner = "Ivancho";
            myPhone.battery = new Battery(BatteryType.NiMH);
            myPhone.battery.HourIdle = 12;
            myPhone.battery.HoursTalk = 520;
            myPhone.display = new Display(12);
            myPhone.display.NumberOfColors = 326;

            // Transfering data and printing
            Console.WriteLine(myPhone.PrintMobileInfo(myPhone.battery, myPhone.display));

            // Iphone4S data:
            string theIPhoneInfo = GSM.IPhone4S;
            Console.WriteLine(theIPhoneInfo);

            // and ETC
            GSM phone = new GSM("Alcatel", "Alacatelov");
            GSMTest.CreateAFewGSMs(5);

            // Adding calls
            myPhone.resentCall = new Call("0898123231");
            Console.WriteLine(myPhone.resentCall.LastNumber);
            myPhone.CallHistory.Add(myPhone.resentCall);

            // Adding a second call
            myPhone.resentCall = new Call("08788765426");

            // Adding the call to the list
            myPhone.CallHistory.Add(myPhone.resentCall);
            foreach (Call talk in myPhone.CallHistory)
            {
                Console.WriteLine(talk.LastNumber);
            }

            // From here on, the adding to the callHistory is automatic
            myPhone.AddAndRemove("add", myPhone);
            myPhone.AddAndRemove("remove", myPhone);
            double totalPrice = myPhone.TotalPriceOfCalls(myPhone);

            // Not working because I don't have thread.sleep or something to make timespan
            Console.WriteLine("Total price: {0}", totalPrice);

            // Clearing the history
            myPhone.ClearHistory();
            GSMCallHistoryTest.GSMTest();
        }