Computer Applications
A library charges a fine for returning a book late after the due date as per the conditions given below:
| No. of days | Fine |
|---|---|
| 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

Answered By
12 Likes
Related Questions
A shopkeeper offers 30% discount on purchasing articles whereas the other shopkeeper offers two successive discounts 20% and 10% for purchasing the same articles. Write a program in Java to compute and display the discounts.
Take the price of an article as the input.Write a program to input the cost price and the selling price of an article. If the selling price is more than the cost price then calculate and display actual profit and profit per cent otherwise, calculate and display actual loss and loss per cent. If the cost price and the selling price are equal, the program displays the message 'Neither profit nor loss'.
A triangle is said to be an 'Equable Triangle', if the area of the triangle is equal to its perimeter. Write a program to enter three sides of a triangle. Check and print whether the triangle is equable or not.
For example, a right angled triangle with sides 5, 12 and 13 has its area and perimeter both equal to 30.A special two-digit number is such that when the sum of its digits is added to the product of its digits, the result is equal to the original two-digit number.
Example: Consider the number 59.
Sum of digits = 5 + 9 = 14
Product of digits = 5 * 9 = 45
Sum of the sum of digits and product of digits = 14 + 45 = 59Write a program to accept a two-digit number. Add the sum of its digits to the product of its digits. If the value is equal to the number input, then display the message "Special two—digit number" otherwise, display the message "Not a special two-digit number".