Sort by

recency

|

1040 Discussions

|

  • + 0 comments

    C++

    int libraryFine(int d1, int m1, int y1, int d2, int m2, int y2) {
        int res = 0;
        if (y1 > y2) {
            res = 10000;
        } else if (y1 == y2 & m1 > m2) {
            res = (m1 - m2) * 500;
        } else if (y1 == y2 & m1 == m2 & d1 > d2) {
            res = (d1 - d2) * 15;
        }
    
        return res;
    }
    
  • + 0 comments

    Java 8 based

        public static int libraryFine(int d1, int m1, int y1, int d2, int m2, int y2) {
        // Write your code here
            int fineWithinSameMonth = 15;
            int fineWithinSameYear = 500;
            if(y1 > y2) {
                return 10000;
            } else if (y1 == y2) {
                if(m1 > m2) {
                    return (m1 - m2) * fineWithinSameYear;
                } else if (m1 == m2 & d1 > d2) {
                    return (d1 - d2) * fineWithinSameMonth;
                }
            }
            return 0;
    
        }
    
  • + 0 comments
     internal class BookReturn
     {
         public DateTime ReturnedOn { get; set; }
         public DateTime DueOn { get; set; }
    
         public BookReturn(string returnedOn, string dueOn)
         {
             var returnedOnValues = returnedOn.Split(" ").Select(ch => int.Parse(ch)).ToArray();
             var dueOnValues = dueOn.Split(" ").Select(ch => int.Parse(ch)).ToArray();
    
             ReturnedOn = new DateTime(returnedOnValues[2], returnedOnValues[1], returnedOnValues[0]);
             DueOn = new DateTime(dueOnValues[2], dueOnValues[1], dueOnValues[0]);
    
         }
    
         public BookReturn(int d1, int m1, int y1, int d2, int m2, int y2)
         {
             ReturnedOn = new DateTime(y1, m1, d1);
             DueOn = new DateTime(y2, m2, d2);
         }
    
         public bool IsLateWithinSameYear => ReturnedOn.Year == DueOn.Year;
    
         public bool IsLateWithinSameMonth => IsLateWithinSameYear && ReturnedOn.Month == DueOn.Month;
    
         public bool IsLateMoreThanAYear => ReturnedOn.Year != DueOn.Year;
    
         public bool IsReturnedOnTime => ReturnedOn.Date <= DueOn.Date;
    
         public int LateFee => Math.Abs(CalculateFee());
    
         private int CalculateFee()
         {
             if (IsReturnedOnTime)
                 return 0;
    
             if (IsLateWithinSameMonth)
             {
                 return 15 * (DueOn.Date - ReturnedOn.Date).Days;
             }
    
             if (IsLateWithinSameYear)
             {
                 return 500 * (DueOn.Month - ReturnedOn.Month);
             }
    
             if (IsLateMoreThanAYear)
             {
                 return 10000;
             }
    
             return 0;
         }
     }
    
  • + 0 comments

    Library fines can sometimes feel like a small but frustrating reminder of overdue responsibilities. It usually happens when a busy schedule makes you forget the return date, and suddenly you’re hit with a penalty. The idea behind fines is not just about money but also encouraging readers to share resources on time so others can enjoy them. In the same way, just as dubai painting contractors focus on precision and deadlines to deliver their work smoothly, returning books on schedule ensures the library runs efficiently. Many people now see these fines as a gentle push toward being more mindful. At the end of the day, it’s about valuing community resources and respecting shared spaces.

  • + 0 comments
    # Library Fine 🧾
    def library_fine(d1, m1, y1, d2, m2, y2):
        return (10000 if y1 > y2 else 
                (m1 - m2) * 500 if y1 == y2 and m1 > m2 else 
                (d1 - d2) * 15 if y1 == y2 and m1 == m2 and d1 > d2 else 
                0)