java program to calculate the fine assuming that a book is returned N days late

Programming Example

A library charges a fine for books returned late. Following are the fines:

First five days : 40 paise per day.

Six to Ten days : 65 paise per day.

Above ten days : 80 paise per day.

Design a program to calculate the fine assuming that a book is returned N days late.

Solution

import java.util.*;
class Fine
{
    public static void main(String arr[])
    {
        int N;
        float f;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the no. of days the book is returned late:");
        N=sc.nextInt();
        if (N<=5)
            f=0.40f*N;
        else if (N<=10)
            f=0.40f*5+(N-5)*0.65f;
        else
            f=0.40f*5+0.65f*5+(N-10)*0.80f;
        System.out.println("Fine="+f);
    }
}
Output


CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad