Library Management System Project In Java With Source Code File
Book book = libraryService.findBookById(bookId); if (book != null) book.setQuantity(book.getQuantity() + 1); issuedBooks.remove(bookId); System.out.println("Book returned successfully.");
public Member(int memberId, String name, String email, String phone) this.memberId = memberId; this.name = name; this.email = email; this.phone = phone;
if (book == null) System.out.println("Book not found."); return; if (member == null) System.out.println("Member not found."); return; if (book.getQuantity() <= 0) System.out.println("Book out of stock."); return; if (issuedBooks.containsKey(bookId)) System.out.println("Book already issued to another member. Please wait for return."); return;
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); Library Management System Project In Java With Source Code
// 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());
public Book(int id, String title, String author, String genre, int quantity) this.id = id; this.title = title; this.author = author; this.genre = genre; this.quantity = quantity;
// Member operations public void addMember(String name, String email, String phone) Member member = new Member(nextMemberId++, name, email, phone); members.add(member); System.out.println("Member registered successfully! ID: " + member.getMemberId()); Book book = libraryService
public Member findMemberById(int id) return members.stream().filter(m -> m.getMemberId() == id).findFirst().orElse(null);
public void showAllMembers() Email package service; import model.Book; import model.Member; import java.util.HashMap; import java.util.Map;
public void showIssuedBooks() if (issuedBooks.isEmpty()) System.out.println("No books currently issued."); return; System.out.println("\nIssued Books (Book ID -> Member ID):"); for (Map.Entry<Integer, Integer> entry : issuedBooks.entrySet()) Book b = libraryService.findBookById(entry.getKey()); Member m = libraryService.findMemberById(entry.getValue()); System.out.println("Book: " + (b != null ? b.getTitle() : "Unknown") + " ID: " + member
public class LibraryService private List<Book> books = new ArrayList<>(); private List<Member> members = new ArrayList<>(); private int nextBookId = 1; private int nextMemberId = 1;
public void showAllBooks() Title
int choice = scanner.nextInt(); scanner.nextLine(); // consume newline
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: ");