- Home
- Chapter 1 - Object Oriented Programming Concepts
- Object Oriented Programming Concepts
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 2 - Introduction to Java
- Introduction to Java
- Multiple Choice Questions
- Assignment Questions
- Chapter 3 - Values and Data Types
- Values and Data Types
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 4 - Operators in Java
- Operators in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 5 - User-Defined Methods
- User-Defined Methods
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 6 - Input in Java
- Input in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 7 - Mathematical Library Methods
- Mathematical Library Methods
- Multiple Choice Questions
- Assignment Questions
- Chapter 8 - Conditional Constructs in Java
- Conditional Constructs in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 9 - Iterative Constructs in Java
- Iterative Constructs in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions and Programs
- Chapter 10 - Nested for loops
- Nested for loops
- Assignment Questions and Programs
- Chapter 11 - Constructors
- Constructors
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 12 - Library Classes
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 13 - Encapsulation and Inheritance
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 14 - Arrays
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 15 - String Handling
- Library Classes
- Multiple Choice Questions
- Assignment Questions
Conditional Constructs in Java
Chapter 8
Conditional Constructs in Java
Class 10 - Logix Kips ICSE Computer Applications with BlueJ
![]() Share with a Friend |
Java Program: Menu Driven Program - City Library Late Fine Calculator
43. The City Library charges late fine from members if the books were not returned on time as per the following table:
|
Number of days late |
Magazines fine per day |
Text books fine per day |
|
Up to 5 days |
Rs. 1 |
Rs. 2 |
|
6 to 10 days |
Rs. 2 |
Rs. 3 |
|
11 to 15 days |
Rs. 3 |
Rs. 4 |
|
16 to 20 days |
Rs. 5 |
Rs. 6 |
|
More than 20 days |
Rs. 6 |
Rs. 7 |
Using the switch statement, write a program in Java to input name of person, number of days late and type of book — 'M' for Magazine and 'T' for Text book. Compute the total fine and display it along with the name of the person.
import java.util.Scanner;
public class LibraryFineCalculator {
public static void main(String[] args) {
// Title
System.out.println("CITY LIBRARY LATE FINE CALCULATOR");
System.out.println("--------------------------------");
Scanner sc = new Scanner(System.in);
System.out.print("Enter name of the person: ");
String name = sc.nextLine();
System.out.print("Enter number of days late: ");
int days = sc.nextInt();
System.out.print("Enter type of book (M for Magazine, T for Text Book): ");
char type = sc.next().toUpperCase().charAt(0);
int finePerDay = 0;
int totalFine;
switch (type) {
case 'M':
if (days <= 5)
finePerDay = 1;
else if (days <= 10)
finePerDay = 2;
else if (days <= 15)
finePerDay = 3;
else if (days <= 20)
finePerDay = 5;
else
finePerDay = 6;
break;
case 'T':
if (days <= 5)
finePerDay = 2;
else if (days <= 10)
finePerDay = 3;
else if (days <= 15)
finePerDay = 4;
else if (days <= 20)
finePerDay = 6;
else
finePerDay = 7;
break;
default:
System.out.println("Invalid book type entered!");
sc.close();
return;
}
totalFine = finePerDay * days;
System.out.println("\nName of Member : " + name);
System.out.println("Total Fine : Rs. " + totalFine);
sc.close();
}
}
Output
Sample Output CITY LIBRARY LATE FINE CALCULATOR -------------------------------- Enter name of the person: Rahul Enter number of days late: 12 Enter type of book (M for Magazine, T for Text Book): T Name of Member : Rahul Total Fine : Rs. 48
📝 Explanation
- User inputs name, days late, and book type
- switch is used for book type selection
- if–else assigns fine per day based on number of days
- Total fine is calculated as:
Total Fine = Days Late × Fine Per Day
- Displays the member’s name and fine amount
- Invalid book type gives an error message
