Exemple #1
0
        public static void Main()
        {
            Battery lionBattery = new Battery("Lion", BatteryType.LiIon, 49, 8);
            Display bigDisplay  = new Display(4.7, 16000000);

            GSM phone = new GSM("Galaxy", "Samsung", 400.78M, "Pesho", lionBattery, bigDisplay);

            Call currentCall = new Call(DateTime.Now.AddDays(6), "0888888888", 156);

            phone.AddCall(currentCall);

            currentCall = new Call(DateTime.Now, "0777777777", 456);
            phone.AddCall(currentCall);

            currentCall = new Call(DateTime.Now.AddHours(100), "0989565690", 345);
            phone.AddCall(currentCall);

            foreach (var call in phone.CallHistory)
            {
                Console.WriteLine("Call date:{0} Phone number:{1} Duration:{2} seconds", call.Date, call.DialledPhoneNumber, call.DurationInSeconds);
            }


            Console.WriteLine("Total call price is: ${0}", phone.CalculateTotalCallPrice());

            long?maxCallDuration = long.MinValue;
            Call longestCall     = new Call(DateTime.Now, "00000000", 0);

            foreach (var currentCallToCheck in phone.CallHistory)
            {
                if (currentCallToCheck.DurationInSeconds > maxCallDuration)
                {
                    maxCallDuration = currentCallToCheck.DurationInSeconds;
                    longestCall     = currentCallToCheck;
                }
            }

            phone.RemoveCall(longestCall);

            Console.WriteLine("Total price without longest call: $" + phone.CalculateTotalCallPrice());

            phone.ClaerCallHistory();

            if (phone.CallHistory.Count == 0)
            {
                Console.WriteLine("Calls cleared!");
            }
        }
    static void Main()
    {
        List <GSM> cellPhones = new List <GSM>();

        GSM currentGSM = new GSM("Galaxy SIV", "Samsung", 999.99, "Ganka", new Battery("normal", BatteryType.LiIon, 500, 250), new Display("5.0\"", 16000000));

        cellPhones.Add(currentGSM);

        currentGSM = new GSM("One", "HTC", 949.99, "Tosho");
        cellPhones.Add(currentGSM);

        currentGSM = new GSM("Lumia", "Nokia", 799.99, "test", new Battery("duracell", BatteryType.NiMh));
        cellPhones.Add(currentGSM);

        foreach (var phone in cellPhones)
        {
            Console.WriteLine(phone.ToString());
        }

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

        currentGSM.AddCall(DateTime.Now, "0883412079", 75);

        Console.WriteLine(currentGSM.CalculateTotalCallPrice(0.50m));
    }
Exemple #3
0
        public static void TestCallHistory()
        {
            StringBuilder sb    = new StringBuilder();
            Manufacturer  nokia = new Manufacturer("Nokia", "USA");
            GSM           lumia = new GSM("Lumia", nokia, 250, new Battery(), new Display());

            lumia.CallHistory.Add(new Call("12345", 230));
            lumia.CallHistory.Add(new Call("12345", 50));
            lumia.CallHistory.Add(new Call("12345", 180));

            sb.AppendLine("Call history: ");
            foreach (var call in lumia.CallHistory)
            {
                sb.AppendLine(call.ToString());
            }

            sb.AppendLine(Constants.Border);

            decimal totalPrice = lumia.CalculateTotalCallPrice(PricePerMinute);

            sb.AppendFormat("Total price all: {0}", totalPrice)
            .AppendLine()
            .AppendLine(Constants.Border);

            sb.AppendLine("To remove: ");
            Call longestCall = FindLongestCall(lumia);

            lumia.CallHistory.Remove(longestCall);

            sb.AppendLine(longestCall.ToString())
            .AppendLine(Constants.Border);

            totalPrice = lumia.CalculateTotalCallPrice(PricePerMinute);
            sb.AppendFormat("Total price after removal: {0}", totalPrice)
            .AppendLine()
            .AppendLine(Constants.Border);

            lumia.CallHistory.Clear();
            sb.AppendLine("Call history after clearing: ");
            foreach (var call in lumia.CallHistory)
            {
                sb.AppendLine(call.ToString());
            }

            Console.WriteLine(sb.ToString());
        }
    static void Main()
    {
        // Initialise an object to the already set static property
        GSM currentGSM = GSM.IPhone4S;

        // Add some calls
        currentGSM.AddCall(DateTime.Now, "12315123", 43);
        currentGSM.AddCall(DateTime.Now, "123156341", 27);
        currentGSM.AddCall(DateTime.Now, "080823874", 132);

        // Get the longest duration call and display details about each call
        int longestDurationIndex = int.MinValue;
        int longestDuration      = int.MinValue;

        for (int i = 0; i < currentGSM.CallHistory.Count; i++)
        {
            Console.WriteLine(currentGSM.CallHistory[i].ToString());
            Console.WriteLine();

            if (currentGSM.CallHistory[i].Duration > longestDuration)
            {
                longestDurationIndex = i;
                longestDuration      = currentGSM.CallHistory[i].Duration;
            }
        }

        // Calculate total call history price
        Console.WriteLine("{0:0.00}", currentGSM.CalculateTotalCallPrice(0.37m));

        // Remove the longest duration call and recalculate the call history price
        currentGSM.DeleteCall(longestDurationIndex);

        Console.WriteLine("{0:0.00}", currentGSM.CalculateTotalCallPrice(0.37m));

        // Clear the call history
        currentGSM.ClearHistory();

        foreach (var call in currentGSM.CallHistory)
        {
            Console.WriteLine(call.ToString());
        }
    }