Ivy Huynh
For this project I built a simple Library Management System in Java to show how OOP concepts work.
It can add books and users, borrow and return books, track transactions, and list all books with availability.
I also added a few small built-in tests to check that borrowing and returning works the way it should.
- Open the project in IntelliJ IDEA.
- Make sure all files are in the same package called
library
. - Run the
Main
class. - You’ll first see the demo (books added, borrowed, returned) and then the tests with pass/fail messages.
Encapsulation
I made the Book
class manage its own availability. You can’t just change the number of copies directly—you have to use checkout()
or checkin()
. This keeps the data safe.
Inheritance
I created a base class User
and then extended it to make Member
and Librarian
. Both share the same common info (id, name) but are still their own types.
Polymorphism
I made an abstract class Transaction
. Then I created BorrowTransaction
and ReturnTransaction
which both extend it and give their own version of getType()
. This way, the program can treat them both as transactions but still know which one is which.
Abstraction (Service Layer)
The LibraryService
class is like the “manager” of everything. The main program doesn’t have to know how books or transactions are stored, it just calls methods like addBook()
, borrowBook()
, or listBooks()
. This makes the program easier to understand and change later.
Book.java
: represents a book and its copiesUser.java
,Member.java
,Librarian.java
: user hierarchyTransaction.java
,BorrowTransaction.java
,ReturnTransaction.java
: transactionsLibraryService.java
: main logic of the systemMain.java
: runs the demo and the tests
This project helped me see how the four OOP pillars actually connect together in code.
Encapsulation keeps my book data safe, inheritance and polymorphism reduce repetition, and abstraction in the service layer keeps my code cleaner. It’s simple, but it shows the main ideas clearly.