static void GSMCallHistoryTest()
        {
            GSM myGSM = new GSM("Samsung", "Galaxy S2", 500, "Jimmy Hendrix", new Battery("HJ/T43456-2012", 190, 12, BatteryType.LiIon), new Display(4.7, 16));

            myGSM.AddCall("22.12.2014", "11:55:32", "0888123456", 132);
            myGSM.AddCall("23.12.2014", "12:56:33", "0888654321", 160);
            myGSM.AddCall("24.12.2014", "13:57:34", "0888456123", 258);
            myGSM.AddCall("25.12.2014", "14:58:35", "0888654123", 400);
            myGSM.AddCall("26.12.2014", "15:59:36", "0888321654", 17);

            Console.WriteLine(myGSM.ShowCallHistory());

            Console.WriteLine("Total call price: {0:F2}", myGSM.CallPrice(0.37M));

            int longestCall = myGSM.CallHistory[0].Duration;
            int longestCallIndex = 0;
            for (int i = 0; i < myGSM.CallHistory.Count; i++)
            {
                int temp = myGSM.CallHistory[i].Duration;
                if (longestCall < temp)
                {
                    longestCall = temp;
                    longestCallIndex = i;
                }
            }

            myGSM.RemoveCall(myGSM.CallHistory[longestCallIndex]);
            // Console.WriteLine("longest call is {0}s and it costs {1:F2}", longestCall, longestCall * 0.37 / 60);
            Console.WriteLine("Total call price after deleting the longest call: {0:F2}", myGSM.CallPrice(0.37M));

            myGSM.ClearCallHistory();
            Console.WriteLine(myGSM.ShowCallHistory());
        }
        static void GSMCallHistoryTest()
        {
            GSM myGSM = new GSM("Samsung", "Galaxy S2", 500, "Jimmy Hendrix", new Battery("HJ/T43456-2012", 190, 12, BatteryType.LiIon), new Display(4.7, 16));

            myGSM.AddCall("22.12.2014", "11:55:32", "0888123456", 132);
            myGSM.AddCall("23.12.2014", "12:56:33", "0888654321", 160);
            myGSM.AddCall("24.12.2014", "13:57:34", "0888456123", 258);
            myGSM.AddCall("25.12.2014", "14:58:35", "0888654123", 400);
            myGSM.AddCall("26.12.2014", "15:59:36", "0888321654", 17);

            Console.WriteLine(myGSM.ShowCallHistory());

            Console.WriteLine("Total call price: {0:F2}", myGSM.CallPrice(0.37M));

            int longestCall      = myGSM.CallHistory[0].Duration;
            int longestCallIndex = 0;

            for (int i = 0; i < myGSM.CallHistory.Count; i++)
            {
                int temp = myGSM.CallHistory[i].Duration;
                if (longestCall < temp)
                {
                    longestCall      = temp;
                    longestCallIndex = i;
                }
            }

            myGSM.RemoveCall(myGSM.CallHistory[longestCallIndex]);
            // Console.WriteLine("longest call is {0}s and it costs {1:F2}", longestCall, longestCall * 0.37 / 60);
            Console.WriteLine("Total call price after deleting the longest call: {0:F2}", myGSM.CallPrice(0.37M));

            myGSM.ClearCallHistory();
            Console.WriteLine(myGSM.ShowCallHistory());
        }
Ejemplo n.º 3
0
        public static void GSMCallHistoryTestMethod()
        {
            // Create an instance
            GSM gsm = new GSM();

            // Add calls
            gsm.AddCallInHistory(new Call(DateTime.Now, "123", 35));
            gsm.AddCallInHistory(new Call(DateTime.Now.AddHours(1), "456", 49));
            gsm.AddCallInHistory(new Call(DateTime.Now.AddMinutes(30), "789", 63));

            // Print call history
            for (int i = 0; i < gsm.CallHistory.Count; i++)
            {
                Console.WriteLine(gsm.CallHistory[i]);
                Console.WriteLine("\n----------------------------");
            }

            // Calculate total price of calls with pricePerMinute = 0.37
            Console.WriteLine(gsm.CalculateTotalPriceOfCalls(0.37));

            // Remove the call with longest duration and calculate the total price again
            // Find the call
            int indexOfMaxCall = 0;
            int maxDuration    = -1;

            for (int i = 0; i < gsm.CallHistory.Count; i++)
            {
                if (gsm.CallHistory[i].Duration > maxDuration)
                {
                    maxDuration    = gsm.CallHistory[i].Duration;
                    indexOfMaxCall = i;
                }
            }

            // Remove the call and calculate the total price again
            gsm.DeleteCallFromHistory(gsm.CallHistory[indexOfMaxCall]);
            Console.WriteLine(gsm.CalculateTotalPriceOfCalls(0.37));

            // Clear the call history
            gsm.ClearCallHistory();
            for (int i = 0; i < gsm.CallHistory.Count; i++)
            {
                Console.WriteLine(gsm.CallHistory[i]);
                Console.WriteLine("\n----------------------------");
            }
        }
Ejemplo n.º 4
0
 public void CallHistoryTest()
 {
     var peshoPhone = new GSM("HD2", "HTC", 100000M, "Pesho",
     new Battery("PeshoBattery", 31231, 31312, BatteryType.LiIon),
     new Display(10f, 20000000));
     peshoPhone.AddCall("739172937193", 105);
     peshoPhone.AddCall("0854646466464", 2000);
     peshoPhone.AddCall("0864646464", 15);
     peshoPhone.AddCall("0888556464", 62);
     peshoPhone.ShowHistory();
     decimal peshoBill = peshoPhone.CalculateTotalPrice(0.37M);
     Console.WriteLine("{0} has to pay {1:F2}{2}", peshoPhone.Owner, peshoBill,
     RegionInfo.CurrentRegion.CurrencySymbol);
     peshoPhone.DeleteCall("0854646466464");
     peshoPhone.ShowHistory();
     peshoBill = peshoPhone.CalculateTotalPrice(0.37M);
     Console.WriteLine("{0} has to pay {1:F2}{2}", peshoPhone.Owner, peshoBill,
     RegionInfo.CurrentRegion.CurrencySymbol);
     peshoPhone.ClearCallHistory();
     peshoPhone.ShowHistory();
 }
 public void GSMTester()
 {
     this.gsmDevice.AddCallToList(new Calls("+359 86 4 121223", new DateTime(), new TimeSpan(0, 5, 1), 0.5));
     this.gsmDevice.AddCallToList(new Calls("+359 86 5 999999", new DateTime(), new TimeSpan(0, 5, 1), 0.5));
     this.gsmDevice.AddCallToList(new Calls("+359 86 6 434343", new DateTime(), new TimeSpan(0, 9, 1), 0.5));
     this.gsmDevice.AddCallToList(new Calls("+359 86 5 888888", new DateTime(), new TimeSpan(0, 5, 1), 0.5));
     this.gsmDevice.AddCallToList(new Calls("+359 86 6 777777", new DateTime(), new TimeSpan(0, 5, 1), 0.5));
     this.gsmDevice.AddCallToList(new Calls("+359 86 5 665566", new DateTime(), new TimeSpan(0, 5, 1), 0.5));
     this.gsmDevice.AddCallToList(new Calls("+359 86 6 555555", new DateTime(), new TimeSpan(0, 6, 1), 0.5));
     gsmDevice.PrintCallHistory();
     gsmDevice.PrintTotalPrice();
     gsmDevice.DeleteLongestCallFromList();
     Console.WriteLine("---------");
     gsmDevice.PrintCallHistory();
     gsmDevice.PrintTotalPrice();
     Console.WriteLine("---------");
     gsmDevice.DeleteLongestCallFromList();
     gsmDevice.PrintCallHistory();
     gsmDevice.PrintTotalPrice();
     gsmDevice.ClearCallHistory();
     gsmDevice.PrintCallHistory();
 }