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
- import java.util.Scanner;
-
- public class Solution {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
-
- int da = in.nextInt();
- int ma = in.nextInt();
- int ya = in.nextInt();
-
- int de = in.nextInt();
- int me = in.nextInt();
- int ye = in.nextInt();
-
- int fine = 0;
-
- if (ya > ye) fine = 10000;
- else if (ya == ye) {
- if (ma > me) fine = (ma - me) * 500;
- else if (ma == me && da > de) fine = (da - de) * 15;
- }
-
- System.out.println(fine);
- }
- }