示例#1
0
        public static void Main()
        {
            var gsms = new List<GSM>
            {
                new GSM("Galaxy 6", "Samsung", 800.00m, new Battery(BatteryType.LiIon, "model", 500, 100), new Display(5.3)),
                new GSM("6", "IPhone", 1200.00m, new Battery(BatteryType.LiIon, "model", 800, 400), new Display()),
                new GSM("Model", "LG", 400.00m, new Battery(BatteryType.NiCd, "model", 300, 100), new Display(4.5)),
                new GSM("Lumia 930", "Nokia", 500.00m, new Battery(BatteryType.NiMH, "model 3", 400, 200), new Display()),
                new GSM("Neshto si", "Sony", 450.00m, new Battery(BatteryType.NiCd, "model", 343, 140), new Display(4.8)),
                new GSM("Galaxy 4", "Samsung", 550.00m, new Battery(BatteryType.LiIon, "model", 400, 150), new Display())
            };

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

            Console.WriteLine(GSM.iPhone4s);

            var testCallsGsm = new GSM();
            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(234), "+359888787878"));
            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(434), "+35988865161"));
            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(2234), "+359887846163"));
            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(624), "+359885525056"));
            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(12352), "+359884651625"));

            Console.WriteLine("Before removing the longest call from call history the price is - {0:F2}", testCallsGsm.CalculatePrice(0.37));

            var longestcall = testCallsGsm.CallHistory.OrderByDescending(x => x.Length).FirstOrDefault();
            testCallsGsm.CallHistory.Remove(longestcall);
            Console.WriteLine("After removing the longest call from call history the price is - {0:F2}", testCallsGsm.CalculatePrice(0.37));
            testCallsGsm.ClearHistory();
            Console.WriteLine("After removing all the calls from call history the price is - {0:F2}", testCallsGsm.CalculatePrice(0.37));
        }
        //Print calls and price.
        static void PrintCalls(GSM phone)
        {
            List<Call> callHistory = phone.CallHistory;
            if (callHistory != null)
            {
                foreach (var call in callHistory)
                {
                    Console.WriteLine();
                    Console.Write("-------Call Start--------");
                    Console.WriteLine(call);
                    Console.WriteLine("-------Call End--------");
                }

                Console.Write("\nTotal Price: ");
                Console.WriteLine(phone.CalculatePrice(0.37m));
            }
            else
            {
                Console.WriteLine("\nEmpty CallHistory!");
            }
        }
示例#3
0
        public static void Main()
        {
            var gsms = new List <GSM>
            {
                new GSM("Galaxy 6", "Samsung", 800.00m, new Battery(BatteryType.LiIon, "model", 500, 100), new Display(5.3)),
                new GSM("6", "IPhone", 1200.00m, new Battery(BatteryType.LiIon, "model", 800, 400), new Display()),
                new GSM("Model", "LG", 400.00m, new Battery(BatteryType.NiCd, "model", 300, 100), new Display(4.5)),
                new GSM("Lumia 930", "Nokia", 500.00m, new Battery(BatteryType.NiMH, "model 3", 400, 200), new Display()),
                new GSM("Neshto si", "Sony", 450.00m, new Battery(BatteryType.NiCd, "model", 343, 140), new Display(4.8)),
                new GSM("Galaxy 4", "Samsung", 550.00m, new Battery(BatteryType.LiIon, "model", 400, 150), new Display())
            };

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

            Console.WriteLine(GSM.iPhone4s);

            var testCallsGsm = new GSM();

            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(234), "+359888787878"));
            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(434), "+35988865161"));
            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(2234), "+359887846163"));
            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(624), "+359885525056"));
            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(12352), "+359884651625"));

            Console.WriteLine("Before removing the longest call from call history the price is - {0:F2}", testCallsGsm.CalculatePrice(0.37));

            var longestcall = testCallsGsm.CallHistory.OrderByDescending(x => x.Length).FirstOrDefault();

            testCallsGsm.CallHistory.Remove(longestcall);
            Console.WriteLine("After removing the longest call from call history the price is - {0:F2}", testCallsGsm.CalculatePrice(0.37));
            testCallsGsm.ClearHistory();
            Console.WriteLine("After removing all the calls from call history the price is - {0:F2}", testCallsGsm.CalculatePrice(0.37));
        }
示例#4
0
        static void Main(string[] args)
        {
            GSM justInstance = new GSM();

            //Testing full parameter ctor
            Console.WriteLine(new string('-', 80));
            GSM Nokia = new GSM("E52", "Nokia", 200.0m, "Ivan", new Battery("2000 mAh", 12.3, 4.5, BatteryType.NiMH), new Display(2.6, 16000000));
            Console.WriteLine("\nTesting full parameter ctor");
            Console.WriteLine(Nokia.ToString());

            //Testing full param ctor with default Battery and Display
            Console.WriteLine(new string('-', 80));
            GSM Nokia1 = new GSM("E52", "Nokia", 200.0m, "Ivan", new Battery(), new Display());
            Console.WriteLine("\nTesting full param ctor with default Battery and Display");
            Console.WriteLine(Nokia1.ToString());

            //Testing partial param ctor
            Console.WriteLine(new string('-', 80));
            GSM Nokia2 = new GSM("E52", "Nokia");
            Console.WriteLine("\nTesting partial param ctor");
            Console.WriteLine(Nokia2.ToString());

            ///////////////////////////TASK 7 tests//////////////////////////////
            Console.WriteLine(new string('-', 80));
            Console.WriteLine("\nTASK 7 TEST START HERE !");
            GSM[] gsmList = new GSM[5];
            for (int i = 0; i < 5; i++)
            {
                gsmList[i] = Nokia;
            }
            foreach (GSM gsm in gsmList)
            {
                Console.WriteLine(gsm.ToString() + "\n");
            }

            Console.WriteLine("\nPrinting static field iPhone4s");
            Console.WriteLine(justInstance.IPhone4s);

            ///////////////////////////TASK 10 tests////////////////////////////
            Console.WriteLine(new string('-', 80));
            Console.WriteLine("\nTASK 10 TEST START HERE !");
            GSM vladosPhone = new GSM("S35", "Siemens", 79.99m, "Vlado", new Battery("750mAh", 72, 6, BatteryType.LiIon), new Display(1.5, 64), null);
            vladosPhone.AddCalltoHistory(new Call("+359888555777",3600));
            vladosPhone.AddCalltoHistory(new Call("0000",0));
            vladosPhone.AddCalltoHistory(new Call("+359888000000",15));
            vladosPhone.AddCalltoHistory(new Call("0888555777",10));
            vladosPhone.AddCalltoHistory(new Call("028685512",20));
            vladosPhone.AddCalltoHistory(new Call("0359887551552",60));
            vladosPhone.PrintCallLog();
            vladosPhone.DeleteCallFromHistory(new Call("+359888555777"));
            vladosPhone.DeleteCallFromHistory(new Call("0000"));
            vladosPhone.DeleteCallFromHistory(new Call("+359888000000"));
            Console.WriteLine("Testing callHistory delete function:");
            vladosPhone.PrintCallLog();
            Console.WriteLine("Testing callHistory clear function:");
            vladosPhone.ClearHistory();
            vladosPhone.PrintCallLog();

            ///////////////////////////TASK 11 tests////////////////////////////
            Console.WriteLine(new string('-', 80));
            Console.WriteLine("\nTASK 11 TEST START HERE !");
            vladosPhone.AddCalltoHistory(new Call("+359888555777", 3600));
            vladosPhone.AddCalltoHistory(new Call("+359888000000", 15));
            vladosPhone.AddCalltoHistory(new Call("0359887551552", 60));
            vladosPhone.CalculatePrice();

            ///////////////////////////TASK 12 tests////////////////////////////
            Console.WriteLine(new string('-', 80));
            Console.WriteLine("\nTASK 12 TEST START HERE !");
            /*  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.
            */
            //Create an instance of the GSM class.
            GSM instance = new GSM();
            // Add few calls.
            instance.AddCalltoHistory(new Call("+359888555777", 3600));
            instance.AddCalltoHistory(new Call("+359888123321", 300));
            instance.AddCalltoHistory(new Call("0359888333222", 80));
            instance.AddCalltoHistory(new Call("028683939", 50));
            instance.AddCalltoHistory(new Call("+123000128937912837", 0));
            // Display the information about the calls.
            instance.PrintCallLog();
            //Assuming that the price per minute is 0.37 calculate and print the total price of the calls in the history.
            instance.CalculatePrice();
            //Remove the longest call from the history and calculate the total price again.
            instance.DeleteCallFromHistory(new Call("+359888555777"));
            instance.CalculatePrice();
            // Finally clear the call history and print it.
            instance.ClearHistory();
            instance.PrintCallLog();
        }