//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.
        public void CallHIstoryTest()
        {
            GSM myGSM = new GSM("galaxy", "samsung", 899.90, "Myself", new Battery("Lion", 40, 30), new Display(200, 2000));
            Call call1 = new Call(DateTime.Now, "0885121350", 345);
            Call call2 = new Call(DateTime.Now, "09876895456764567", 34);
            Call call3 = new Call(DateTime.Today, "87678875678", 20);

            List<uint> currHistoryDuration = new List<uint>();
            currHistoryDuration.Add((uint)call1.Duration);
            currHistoryDuration.Add((uint)call2.Duration);
            currHistoryDuration.Add((uint)call3.Duration);

            int sum = 0;
            for (int i = 0; i < currHistoryDuration.Count; i++)
            { sum += (int)currHistoryDuration[i]; }

            double spendMoney = (sum / 60) * 0.37;
            Console.WriteLine("Spent money for calls: {0}", spendMoney);

            List<Call> history = new List<Call>();
            history.Add(call1);
            history.Add(call2);
            history.Add(call3);
            //Remove the longest call from the history and calculate the total price again.
            history.OrderByDescending(s => s.Duration.Value);
            history.RemoveAt(0);

            int sumNew = 0;
            for (int i = 0; i < history.Count; i++)
            { sumNew += (int)history[i].Duration; }

            double finallyMoneySpend = (sum / 60) * 0.37;

            //Finally clear the call history and print it.
            foreach(var item in history)
            {
                Console.WriteLine(item.Date);
                Console.WriteLine(item.DailledPhone);
                Console.WriteLine(item.Duration);
            }

            history.Clear();
        }
예제 #2
0
        static void Main()
        {
            // 7. test GSM class

            Console.WriteLine("Task 7: Write a class GSMTest to test the GSM class");

            Battery battery = new Battery("LiLon 2200", 20, 5);
            Display display = new Display(5, 1000000000);
            GSM tel1 = new GSM("S5mini", "Samsung", 3.2, "i", battery, display);
            GSM tel2 = new GSM("Alpha 5", "Samsung", 3.2, "i", battery, display);
            GSM tel3 = new GSM("Xperia Z", "Sony", 700, "Dwayne Johnson", battery, display);

            GSM[] telephones = new GSM[] { tel1, tel2, tel3 };

            foreach (GSM tel in telephones)
            {
                Console.WriteLine(tel);
            }

            Console.WriteLine(GSM.iPhone4S);
        }
예제 #3
0
        static void Main()
        {
            GSM test1 = new GSM("Samsung", "Samsung C&T Corporation", 140000, "HappyOwner",
                        new Battery("High-Tech-Battery", 1000, 10000),
                        new Display(1000, 16000000));

            GSM test2 = new GSM("Ung", "Samsung C&T Corporation", 140000, "HappyOwner",
                        new Battery("High", 1000, 10000),
                        new Display(1000, 16000000));

            GSM test3 = new GSM("Sony", "Sony Corporation", 100, "Me&Myself", new Battery(), new Display());

            GSM[] allPhones = { test1, test2, test3 };

            foreach (var gsm in allPhones)
            {
                Console.WriteLine(gsm);
            }

            Console.WriteLine(GSM.iPhone4S.ToString());

            GSMCallHistoryTest test = new GSMCallHistoryTest();
            test.CallHIstoryTest();
        }