Library Management System Project In Java With Source Code Apr 2026
public class LibraryService private List<Book> books = new ArrayList<>(); private List<Member> members = new ArrayList<>(); private int nextBookId = 1; private int nextMemberId = 1;
private LibraryService libraryService;
public void showAllMembers() Email package service; import model.Book; import model.Member; import java.util.HashMap; import java.util.Map; Library Management System Project In Java With Source Code
while (true) System.out.println("\n===== LIBRARY MANAGEMENT SYSTEM ====="); System.out.println("1. Add Book"); System.out.println("2. View All Books"); System.out.println("3. Search Book by Title"); System.out.println("4. Register Member"); System.out.println("5. View All Members"); System.out.println("6. Issue Book"); System.out.println("7. Return Book"); System.out.println("8. View Issued Books"); System.out.println("9. Exit"); System.out.print("Enter choice: ");
public class TransactionService private Map<Integer, Integer> issuedBooks = new HashMap<>(); // bookId -> memberId Search Book by Title"); System
package service; import model.Book; import model.Member; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors;
Share it with your fellow developers and leave a comment below! Issue Book"); System
import service.LibraryService; import service.TransactionService; import java.util.List; import java.util.Scanner; import model.Book; public class Main public static void main(String[] args) LibraryService libraryService = new LibraryService(); TransactionService transactionService = new TransactionService(libraryService); Scanner scanner = new Scanner(System.in);
public void issueBook(int bookId, int memberId) Book book = libraryService.findBookById(bookId); Member member = libraryService.findMemberById(memberId);
// Book operations public void addBook(String title, String author, String genre, int quantity) Book book = new Book(nextBookId++, title, author, genre, quantity); books.add(book); System.out.println("Book added successfully! ID: " + book.getId());
switch (choice) case 1: System.out.print("Title: "); String title = scanner.nextLine(); System.out.print("Author: "); String author = scanner.nextLine(); System.out.print("Genre: "); String genre = scanner.nextLine(); System.out.print("Quantity: "); int qty = scanner.nextInt(); libraryService.addBook(title, author, genre, qty); break; case 2: libraryService.showAllBooks(); break; case 3: System.out.print("Enter title to search: "); String searchTitle = scanner.nextLine(); List<Book> results = libraryService.searchBookByTitle(searchTitle); if (results.isEmpty()) System.out.println("No books found."); else results.forEach(System.out::println); break; case 4: System.out.print("Name: "); String name = scanner.nextLine(); System.out.print("Email: "); String email = scanner.nextLine(); System.out.print("Phone: "); String phone = scanner.nextLine(); libraryService.addMember(name, email, phone); break; case 5: libraryService.showAllMembers(); break; case 6: System.out.print("Book ID: "); int bId = scanner.nextInt(); System.out.print("Member ID: "); int mId = scanner.nextInt(); transactionService.issueBook(bId, mId); break; case 7: System.out.print("Book ID to return: "); int retId = scanner.nextInt(); transactionService.returnBook(retId); break; case 8: transactionService.showIssuedBooks(); break; case 9: System.out.println("Exiting system. Goodbye!"); scanner.close(); System.exit(0); default: System.out.println("Invalid choice. Try again.");