Loading...
Loading...
A library fines late returns. A member has 14 free days, then pays Rs. 5 a day, at most Rs. 500. A student has 21 free days and a cap of Rs. 200. A research scholar is a student who pays only Rs. 2 a day. Faculty have 30 free days, pay Rs. 1 a day and at most Rs. 100. Write Member with freeDays(), perDay(), maxFine() and one fine(days) that uses them; the other classes override only what differs.
MEMBER, STUDENT, SCHOLAR or FACULTY), a one-word name and the days the book was kept.<name> <fine> for each return, then Total <sum>.Example
Input
4 MEMBER Rohan 20 STUDENT Diya 40 SCHOLAR Arjun 40 FACULTY Kavya 45
Output
Rohan 30 Diya 95 Arjun 38 Kavya 15 Total 178
Diya: 19 late days × 5 = 95. Arjun is a student with Rs. 2 a day: 38.
Try the problem first. Open one hint at a time.
fine(days): long late = Math.max(0, days - freeDays()); return Math.min(late * perDay(), maxFine());.
Scholar extends Student and overrides only perDay(); it inherits the student's free days and cap.
Each hook is a tiny method; fine in Member is never overridden.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor