• + 0 comments

    ` C# CSharp

    static void Main(string[] args)
    {
        // Read and assign the returned and due dates
        DateTime returnedDate = AssignDate(Console.ReadLine());
        DateTime dueDate = AssignDate(Console.ReadLine());
    
        // Calculate and display the fine
        if (returnedDate <= dueDate)
        {
            Console.WriteLine(0); // No fine if returned on or before the due date
        }
        else
        {
            int fine = 0;
    
            if (returnedDate.Year > dueDate.Year)
            {
                // Fine is fixed at 10000 if the return is in a different year
                fine = 10000;
            }
            else if (returnedDate.Month > dueDate.Month)
            {
                // Fine for being late by months within the same year
                fine = 500 * (returnedDate.Month - dueDate.Month);
            }
            else if (returnedDate.Day > dueDate.Day)
            {
                // Fine for being late by days within the same month and year
                fine = 15 * (returnedDate.Day - dueDate.Day);
            }
    
            Console.WriteLine(fine);
        }
    }
    
    // Method to parse input and return a DateTime object
    public static DateTime AssignDate(string dateInput)
    {
        string[] dateSplit = dateInput.Split(' ');
        int day = Convert.ToInt32(dateSplit[0]);
        int month = Convert.ToInt32(dateSplit[1]);
        int year = Convert.ToInt32(dateSplit[2]);
    
        return new DateTime(year, month, day); // Construct and return the DateTime
    }