Library management system
A console app to manage books and members: issue, return, fines and search, designed with clean classes.
What you'll learn
- âClasses, encapsulation and interfaces
- âArrayList and HashMap
- âDates with java.time
What you'll build
- âAdd, search and remove books
- âRegister members
- âIssue and return with due dates
- âFine of âđ2 per late day
Step-by-step guide
- 1
Model the classes
Book (isbn, title, author, available), Member (id, name), Loan (book, member, issueDate, dueDate, returnDate).
- 2
Create a Library service
Hold Map<String, Book> books, Map<Integer, Member> members and List<Loan> loans; put all rules here, not in main.
- 3
Issue a book
Check the book exists and is available, the member has fewer than 3 books, then create a Loan with dueDate = LocalDate.now().plusDays(14).
- 4
Return and fines
Set returnDate; fine = ChronoUnit.DAYS.between(dueDate, returnDate) * 2 if positive.
- 5
Search
Use streams: books.values().stream().filter(b -> b.getTitle().toLowerCase().contains(q)).toList().
- 6
Menu
A Scanner loop in Main with options 1â7; catch InputMismatchException for bad input.
- 7
Save data
Persist books and members to CSV files on exit and load them at start (or use Java serialization).
ð Make it stand out
- +Store data in MySQL with JDBC
- +Add a Swing or JavaFX GUI
- +Write JUnit tests for the fine rules