0% found this document useful (0 votes)
3 views

Java Pbl PDF

The Library Management System is a Java application designed to manage library inventory efficiently, offering functionalities like book management, inventory display, search, and check in/out features. It provides a user-friendly interface for librarians and patrons to navigate and perform various tasks related to book management. The system enhances accessibility to library resources and improves overall efficiency in library operations.

Uploaded by

riddhiybansal04
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Java Pbl PDF

The Library Management System is a Java application designed to manage library inventory efficiently, offering functionalities like book management, inventory display, search, and check in/out features. It provides a user-friendly interface for librarians and patrons to navigate and perform various tasks related to book management. The system enhances accessibility to library resources and improves overall efficiency in library operations.

Uploaded by

riddhiybansal04
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

LIBRARY MANAGEMENT SYSTEM

INTRODUCTION
The Library Management System is a Java application designed to efficiently manage
the inventory of a library. It provides a user-friendly interface for librarians and
patrons to perform various tasks related to book management. This system offers
functionalities like adding new books to the library, updating book information,
checking in/out books, and searching for books based on titles, authors, or genres.

KEY FEATURES :

1. Book Management: Librarians can easily add new books to the library
inventory. Each book is associated with its title, author, and genre information.
2. Inventory Display: The system allows users to display the complete inventory
of the library, showing details such as book title, author, genre, and availability
status (checked in or checked out).
3. Search Functionality: Users can search for books by entering keywords
related to titles, authors, or genres. The system then provides search results
matching the entered query, facilitating easy access to desired books.
4. Check In/Out: Patrons can check out books they wish to borrow, marking
them as unavailable for other patrons. Likewise, they can check in books they
have borrowed, making them available for other users.
5. User-Friendly Interface: The system features a simple and intuitive interface,
making it easy for both librarians and patrons to navigate and perform
necessary actions.

Overall, the Library Management System streamlines the book management process,
enhances accessibility to library resources, and improves the overall efficiency of
library operations. Whether it's adding new books, updating information, or
facilitating book transactions, this system provides a robust solution for effective
library management.
CODE
import java.util.*;

class Book {
private String title;
private String author;
private String genre;
private boolean checkedOut;

public Book(String title, String author, String genre) {


this.title = title;
this.author = author;
this.genre = genre;
this.checkedOut = false;
}

public String getTitle() {


return title;
}

public String getAuthor() {


return author;
}

public String getGenre() {


return genre;
}

public boolean isCheckedOut() {


return checkedOut;
}

public void setCheckedOut(boolean checkedOut) {


this.checkedOut = checkedOut;
}
}

class Library {
private ArrayList<Book> books;

public Library() {
books = new ArrayList<>();
}

public void addBook(Book book) {


books.add(book);
}

public void displayBooks() {


System.out.println("Library Inventory:");
for (Book book : books) {
System.out.println("Title: " + book.getTitle() + ", Author: " + book.getAuthor() + ",
Genre: " + book.getGenre() + ", Checked Out: " + book.isCheckedOut());
}
}

public void searchBook(String query) {


System.out.println("Search Results:");
for (Book book : books) {
if (book.getTitle().equalsIgnoreCase(query) ||
book.getAuthor().equalsIgnoreCase(query) || book.getGenre().equalsIgnoreCase(query)) {
System.out.println("Title: " + book.getTitle() + ", Author: " + book.getAuthor() + ",
Genre: " + book.getGenre() + ", Checked Out: " + book.isCheckedOut());
}
}
}

public void checkOutBook(String title) {


for (Book book : books) {
if (book.getTitle().equalsIgnoreCase(title) && !book.isCheckedOut()) {
book.setCheckedOut(true);
System.out.println("You have checked out the book: " + book.getTitle());
return;
}
}
System.out.println("Sorry, the book is either not available or already checked out.");
}

public void checkInBook(String title) {


for (Book book : books) {
if (book.getTitle().equalsIgnoreCase(title) && book.isCheckedOut()) {
book.setCheckedOut(false);
System.out.println("You have checked in the book: " + book.getTitle());
return;
}
}
System.out.println("Sorry, the book is either not checked out or doesn't exist in the
library.");
}
}

public class LibraryManagementSystem {


public static void main(String[] args) {
Library library = new Library();
Scanner scanner = new Scanner(System.in);

// Adding initial books


library.addBook(new Book("The Great Gatsby", "F. Scott Fitzgerald", "Fiction"));
library.addBook(new Book("To Kill a Mockingbird", "Harper Lee", "Fiction"));
library.addBook(new Book("1984", "George Orwell", "Dystopian"));

boolean exit = false;


while (!exit) {
System.out.println("\nWelcome to Library Management System");
System.out.println("1. Display Books");
System.out.println("2. Search Books");
System.out.println("3. Add New Book");
System.out.println("4. Check Out a Book");
System.out.println("5. Check In a Book");
System.out.println("6. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline

switch (choice) {
case 1:
library.displayBooks();
break;
case 2:
System.out.print("Enter title, author, or genre to search: ");
String query = scanner.nextLine();
library.searchBook(query);
break;
case 3:
System.out.println("Enter book details:");
System.out.print("Title: ");
String title = scanner.nextLine();
System.out.print("Author: ");
String author = scanner.nextLine();
System.out.print("Genre: ");
String genre = scanner.nextLine();
library.addBook(new Book(title, author, genre));
System.out.println("Book added successfully.");
break;
case 4:
System.out.print("Enter the title of the book to check out: ");
String checkOutTitle = scanner.nextLine();
library.checkOutBook(checkOutTitle);
break;
case 5:
System.out.print("Enter the title of the book to check in: ");
String checkInTitle = scanner.nextLine();
library.checkInBook(checkInTitle);
break;
case 6:
exit = true;
System.out.println("Thank you for using Library Management System.");
break;
default:
System.out.println("Invalid choice. Please enter a number between 1 and 6.");
}
}
scanner.close();
}
}

In this code, two classes are defined: Book and Library. The Book class represents a
book with its properties (title, author, genre, checked-out status) and getters/setters.
The Library class manages the book inventory and provides methods for adding
books, updating information, checking in/out books, and searching based on
different criteria.

The main method in the LibraryManagementSystem class serves as the interactive


user interface, allowing the user to perform different operations on the library's
inventory. The user is presented with a menu of options and can enter their choice
via the keyboard. The program then executes the corresponding functionality based
on the user's selection.

To run the program, the LibraryManagementSystem class is compiled and executed.


The program will provide a text-based menu for interacting with the library
management system.
OUTPUT

You might also like