Library Book Management System - Java Project
Project Statement Question
Title: Library Book Management System (Java Console Application)
Problem Statement:
Design and develop a console-based Java application named "Library Book Management
System" that simulates basic book management operations in a library. The system should
allow users to:
1. Add new book details including title, author, and publication year.
2. View all the books currently available in the system.
3. Search for books by matching keywords in the title or author name.
4. Delete a book from the system using its title.
5. Exit the application safely.
The system must be menu-driven and should provide appropriate prompts for user input.
The application should use core Java features such as:
- Classes and Objects
- ArrayList for data storage
- Scanner class for input
- Loops, Conditional Statements, and Methods
(Optional: File I/O can be used to persist data)
Objective:
Build a functional and user-friendly system that demonstrates object-oriented
programming and data handling using basic Java.
Project Overview
This is a basic Java console-based project named 'Library Book Management System'.
The system allows users to perform the following operations:
1. Add new books to the library
2. View all existing books
3. Search books by title or author
4. Delete a book by title
5. Exit the application
The project uses core Java concepts like classes, objects, ArrayLists, Scanner for
input, and conditional logic.
Book.java
Library Book Management System - Java Project
public class Book {
String title;
String author;
int year;
public Book(String title, String author, int year) {
this.title = title;
this.author = author;
this.year = year;
}
public void displayBook() {
System.out.println("Title: " + title);
System.out.println("Author: " + author);
System.out.println("Year: " + year);
System.out.println("-------------------------");
}
}
Library.java
import java.util.ArrayList;
import java.util.Scanner;
public class Library {
ArrayList<Book> books = new ArrayList<>();
Scanner sc = new Scanner(System.in);
public void addBook() {
System.out.print("Enter Book Title: ");
String title = sc.nextLine();
System.out.print("Enter Author Name: ");
String author = sc.nextLine();
System.out.print("Enter Publication Year: ");
int year = sc.nextInt();
sc.nextLine(); // consume newline
books.add(new Book(title, author, year));
System.out.println("Book added successfully!");
}
public void viewBooks() {
if (books.isEmpty()) {
System.out.println("No books available.");
} else {
for (Book b : books) {
b.displayBook();
}
}
Library Book Management System - Java Project
public void searchBook() {
System.out.print("Enter keyword to search (title/author): ");
String keyword = sc.nextLine().toLowerCase();
boolean found = false;
for (Book b : books) {
if (b.title.toLowerCase().contains(keyword) ||
b.author.toLowerCase().contains(keyword)) {
b.displayBook();
found = true;
}
}
if (!found) System.out.println("No matching book found.");
}
public void deleteBook() {
System.out.print("Enter title of the book to delete: ");
String title = sc.nextLine();
for (int i = 0; i < books.size(); i++) {
if (books.get(i).title.equalsIgnoreCase(title)) {
books.remove(i);
System.out.println("Book deleted successfully.");
return;
}
}
System.out.println("Book not found.");
}
}
Main.java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Library library = new Library();
Scanner sc = new Scanner(System.in);
int choice;
do {
System.out.println("==== Library Book Management ====");
System.out.println("1. Add Book");
System.out.println("2. View Books");
System.out.println("3. Search Book");
System.out.println("4. Delete Book");
System.out.println("5. Exit");
System.out.print("Enter your choice: ");
Library Book Management System - Java Project
choice = sc.nextInt();
sc.nextLine(); // consume newline
switch (choice) {
case 1: library.addBook(); break;
case 2: library.viewBooks(); break;
case 3: library.searchBook(); break;
case 4: library.deleteBook(); break;
case 5: System.out.println("Exiting..."); break;
default: System.out.println("Invalid choice. Try again.");
}
} while (choice != 5);
sc.close();
}
}