KnowledgeBoat Logo
|

Computer Applications

A library charges a fine for returning a book late after the due date as per the conditions given below:

No. of daysFine
First five days₹ 2.00 per day
Six to ten days₹ 5.00 per day
Above ten days₹ 10.00 per day

Design a program in Java assuming that a book is returned N days late. Input the value of N using the Scanner class. Calculate and display the fine to be paid to the library.

Java

Input in Java

28 Likes

Answer

import java.util.*;

public class KboatLibraryFine
{
    public static void main(String args[])
    {
        Scanner in = new Scanner(System.in);
        
        System.out.print("Enter the number of days : ");
        int n = in.nextInt();
        
        double fine = 0.0;
        
        if (n <= 5)
            fine = n * 2.0 ;
        else if (n <= 10)
            fine = 10 + (n - 5) * 5.0 ;
        else
            fine = 10 + 25 + (n - 10) * 10 ;
            
        System.out.println("Fine to be paid = ₹" + fine);
    }
}

Output

BlueJ output of A library charges a fine for returning a book late after the due date as per the conditions given below: Design a program in Java assuming that a book is returned N days late. Input the value of N using the Scanner class. Calculate and display the fine to be paid to the library.

Answered By

12 Likes


Related Questions