Java Day 26: Nested Logic




Your local library needs your help! Given the expected and actual return dates for a library book, create a program that calculates the fine (if any). The fee structure is as follows:

If the book is returned on or before the expected return date, no fine will be charged (i.e. fine=0) .
If the book is returned after the expected return day but still within the same calendar month and year as the expected return date, fine= 15 Hackos x number of days late.
If the book is returned after the expected return month but still within the same calendar year as the expected return date, the fine= 500Hackos x number of days late.
If the book is returned after the calendar year in which it was expected, there is a fixed fine of 10000 Hackos



  1. import java.util.Scanner;
  2. public class Solution {
  3. public static void main(String[] args) {
  4. Scanner in = new Scanner(System.in);
  5. int da = in.nextInt();
  6. int ma = in.nextInt();
  7. int ya = in.nextInt();
  8. int de = in.nextInt();
  9. int me = in.nextInt();
  10. int ye = in.nextInt();
  11. int fine = 0;
  12. if (ya > ye) fine = 10000;
  13. else if (ya == ye) {
  14. if (ma > me) fine = (ma - me) * 500;
  15. else if (ma == me && da > de) fine = (da - de) * 15;
  16. }
  17. System.out.println(fine);
  18. }
  19. }
download android app

Popular HackerRank Java Solutions








codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube