Library Management System Using Java With Source Code

Library Management System Using Java​

Abstract:

library management system would be to create a separate class for handling the catalog of books, and another class for handling the individual books. This would allow for better organization and separation of concerns, as well as making the code more reusable. The Library class holds a list of all the books in the library and has methods for adding and removing books, as well as displaying all the books in the library. The LibraryManagementSystem class handles the user interface and communication between the Book and Library classes, using a Scanner object to get user input and controlling the overall flow of the program

Introduction:

Learning Management System, this project build on Java is a great way to update the record, monitor and add books, search for the required ones, taking care of the issue date and return date. It comes with basic features like creating a new record and updating and deleting it. 

Explanation:

A Library Management System is a software application that helps to manage and organize the daily operations of a library. 

Before we begin, let’s first define the main components of our LMS. We will need to create a Book class that will hold information about each book in the library, including the title, author, ISBN, and availability status.  Finally, you will create a LibraryManagementSystem class that will handle the user interface and communication between the Book and Library classes.

Book class will have four instance variables: Title, Author, ISBN, and Availability. These variables will hold the respective information about each book. We will also include a constructor that will take in the values for each variable and set them to the corresponding instance variables.

Source Code:

Get Discount on Top Educational Courses

Brand NameDiscount InformationCoupon Codes Link
Educative.io20% discount on Educative courses and plans
W3Schools20% discount on W3Schools courses
KodeKloud10% discount on KodeKloud courses and plans
GeeksforGeeks30% discount on GeeksforGeeks courses
Target Test Prep20% discount on Target Test Prep
Coding Ninjas₹5000 discount on Coding Ninjas courses
Skillshare40% discount on Skillshare
DataCamp50% discount on DataCamp
365 Data Science57% discount on 365 Data Science Plans
Get SmarterFlat 20% discount on Get Smarter courses
SmartKeedaFlat 40% discount on SmartKeeda courses
StackSocial20% discount on StackSocial courses
				
					import java.util.ArrayList;
import java.util.Scanner;

class Book {
    String title;
    String author;
    String ISBN;
    boolean availability;

    public Book(String title, String author, String ISBN, boolean availability) {
        this.title = title;
        this.author = author;
        this.ISBN = ISBN;
        this.availability = availability;
    }
}

class Library {
    ArrayList books;

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

    public void addBook(Book book) {
        books.add(book);
    }

    public void removeBook(String ISBN) {
        for (Book book : books) {
            if (book.ISBN.equals(ISBN)) {
                books.remove(book);
                break;
            }
        }
    }

    public void displayBooks() {
        for (Book book : books) {
            System.out.println("Title: " + book.title);
            System.out.println("Author: " + book.author);
            System.out.println("ISBN: " + book.ISBN);
            System.out.println("Availability: " + book.availability);
            System.out.println();
        }
    }
}

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

        while (true) {
            System.out.println("1. Add Book");
            System.out.println("2. Remove Book");
            System.out.println("3. Display Books");
            System.out.println("4. Exit");

            int choice = scanner.nextInt();

            if (choice == 1) {
                scanner.nextLine(); // to consume the newline character
                System.out.print("Enter title: ");
                String title = scanner.nextLine();
                System.out.print("Enter author: ");
                String author = scanner.nextLine();
                System.out.print("Enter ISBN: ");
                String ISBN = scanner.nextLine();
                System.out.print("Enter availability: ");
                boolean availability = scanner.nextBoolean();
                library.addBook(new Book(title, author, ISBN, availability));
            } else if (choice == 2) {
                scanner.nextLine(); // to consume the newline character
                System.out.print("Enter ISBN: ");
                String ISBN = scanner.nextLine();
                library.removeBook(ISBN);
            } else if (choice == 3) {
                library.displayBooks();
            } else if (choice == 4) {
                break;
            }
        }

        scanner.close();
    }
}
				
			

Next, we will create the Library class. This class will have an instance variable called book that will hold a list of all the books in the library.  We will also include methods for adding and removing books from the list, as well as a method for displaying all the books in the library.

Finally, we will create the LibraryManagementSystem class that will handle the user interface and communication between the Book and Library classes. This class will use a Scanner object to get user input and will include a main method that will handle the overall flow of the program.

Output:

Library Management System Using Java
Library Management System Using Java

Find More Projects

how to create a video background with html CSS JavaScript Introduction Hello friends, you all are welcome to today’s new blog post. …

Auto Text Effect Animation Using Html CSS & JavaScript Introduction Hello friends, welcome to today’s new blog post. Today we have created …

Windows 12 Notepad Using Python Introduction: In this article, we will create a Windows 12 Notepad using Python. If you are a …

Animated Search Bar using Html CSS And JavaScript Introduction Hello friends, all of you developers are welcome to today’s beautiful blog post. …

Best Quiz Game Using HTML CSS And JavaScript Introduction Hello coders, welcome to another new blog. Today in this article we’ll learn …

Tower Blocks Game Using HTML CSS And JavaScript Introduction Hello coders, welcome to another new blog. Today in this blog we’ll learn …