Class Library

java.lang.Object
com.miniproject.two.Library

public class Library extends Object
Library Management System - Library Class This class represents a Library that contains a collection of books and provides various methods to manage them. The Library allows adding, removing, searching, borrowing, and returning books. It also supports displaying all books in the collection. The Library class includes methods for:
  • Adding a new book with details like title, author, ISBN, genre, publication format, and more.
  • Removing books based on a search term.
  • Searching for books using a search term.
  • Displaying all books in the library.
  • Borrowing a book by ISBN and recording the borrower's name.
  • Returning a borrowed book by ISBN.
Input validation includes:
  • Ensuring the ISBN is valid.
  • Handling availability status updates when borrowing and returning books.
The program uses ANSI escape codes for color formatting in the console.
Since:
2024-06-25
Version:
1.0
  • Constructor Details

    • Library

      public Library()
  • Method Details

    • getBooks

      public List<Book> getBooks()
    • addBook

      public void addBook(String title, String author, String isbn, String genre, String subgenre, String nationality, String publicationFormat, int publishedYear, String publisherName, String deweyDecimal, boolean isAvailable, String borrowedByUserName)
      Adds a new book to the library.
      Parameters:
      title - the title of the book
      author - the author of the book
      isbn - the ISBN of the book
      genre - the genre of the book
      subgenre - the subgenre of the book
      nationality - the nationality of the book
      publicationFormat - the publication format of the book
      publishedYear - the year the book was published
      publisherName - the name of the publisher
      deweyDecimal - the Dewey decimal classification of the book
      isAvailable - whether the book is available or not
      borrowedByUserName - the username of the user who borrowed the book
    • updateBook

      public void updateBook(int bookId, String title, String author, String isbn, String genre, String subgenre, String nationality, String publicationFormat, int publishedYear, String publisherName, String deweyDecimal, boolean isAvailable, String borrowedByUserName)
      Updates the details of a book in the library.
      Parameters:
      bookId - the ID of the book to be updated
      title - the new title of the book
      author - the new author of the book
      isbn - the new ISBN of the book
      genre - the new genre of the book
      subgenre - the new subgenre of the book
      nationality - the new nationality of the book
      publicationFormat - the new publication format of the book
      publishedYear - the new year the book was published
      publisherName - the new name of the publisher
      deweyDecimal - the new Dewey decimal classification of the book
      isAvailable - the new availability status of the book
      borrowedByUserName - the new username of the user who borrowed the book
    • removeBook

      public List<Book> removeBook(String searchTerm)
      Removes books from the library based on the provided search term.
      Parameters:
      searchTerm - the term used for searching books
      Returns:
      a list of books that match the search criteria
    • removeBookById

      public List<Book> removeBookById(int bookId)
      Removes a book from the library based on the provided book ID.
      Parameters:
      bookId - the ID of the book to be removed
      Returns:
      a list of books that match the provided book ID
    • searchBooks

      public List<Book> searchBooks(String searchTerm)
      Searches for books in the library based on the provided search term.
      Parameters:
      searchTerm - the term used for searching books
      Returns:
      a list of books that match the search criteria
    • showBooks

      public List<Book> showBooks()
      Displays all the books in the library. This function checks if the list of books is empty. If it is, it prints a message indicating that no books were found. If the list is not empty, it prints a message indicating that all books are being shown, followed by the title, author, ISBN, publication year, and genre of each book in the list.
      Returns:
      the list of all books in the library
    • showBookById

      public List<Book> showBookById(int bookId)
      Displays books in the library based on the provided book ID.
      Parameters:
      bookId - the ID of the book to be displayed
      Returns:
      a list of books that match the provided book ID
    • borrowBook

      public boolean borrowBook(String ISBN, String borrowerName)
      Borrows a book from the library based on the provided ISBN and borrower name.
      Parameters:
      ISBN - the ISBN of the book to be borrowed
      borrowerName - the name of the borrower
      Returns:
      true if the book was successfully borrowed, false otherwise
    • returnBook

      public boolean returnBook(String ISBN)
      Returns a book to the library based on the provided ISBN.
      Parameters:
      ISBN - the ISBN of the book to be returned
      Returns:
      true if the book was successfully returned, false otherwise