コード例 #1
0
    public static void Main()
    {
        // Create the phone
        GSM myPhone = new GSM("Nexus 5", "Google");
        Console.WriteLine("Your phone: {0} {1}\n", myPhone.Manufacturer, myPhone.Model);

        // Let's make some random calls
        int numCalls = 5;
        Random rand = new Random();
        int callNumber;
        int callDuration;
        for (int i = 0; i < numCalls; i++)
        {
            callNumber = rand.Next(884000000, 899999999);
            callDuration = rand.Next(30, 300);

            myPhone.OpenCall("+359" + callNumber);
            myPhone.CloseCall(callDuration);
        }

        // Display the call history
        DisplayCallHistory(myPhone);

        // Display total cost of all calls
        decimal pricePerMinute = 0.37m;
        PrintTotalCost(myPhone, pricePerMinute);

        // Get the longest call
        int longestCallIndex = 0;
        for (int i = 0; i < myPhone.CallHistory.Count; i++)
        {
            if (myPhone.CallHistory[i].Duration > myPhone.CallHistory[longestCallIndex].Duration)
            {
                longestCallIndex = i;
            }
        }

        // Remove the longest call
        myPhone.DeleteCall(longestCallIndex);

        // Display total cost of all calls
        Console.WriteLine("\nAfter removing the longest call from the history:");
        PrintTotalCost(myPhone, pricePerMinute);

        // Clear the call history and print it. 
        Console.WriteLine("\nClear call history...");
        myPhone.ClearCallHistory();
        Console.WriteLine();
        DisplayCallHistory(myPhone);      
    }