A clean, modular Java console application designed to practice Object-Oriented Programming best practices, specifically Encapsulation and the Single Responsibility Principle.
This project simulates the core operations of a physical library. Unlike basic "Hello World" scripts, this application separates the Data Layer (Book), Logic Layer (Library), and Presentation Layer (LibraryApp) to simulate a real-world software architecture.
It demonstrates how to manage in-memory state, handle user input validation, and manipulate relationships between objects.
The project follows a "Separation of Concerns" philosophy:
Book.java(Model): A POJO (Plain Old Java Object) using Encapsulation (private fields, public getters/setters) to protect data integrity.Library.java(Service): Manages the business logic. It handles theArrayListcollection and usesstaticvariables to track global inventory state.LibraryApp.java(View/Controller): Handles the UI (Console) and User Input (Scanner), keeping the core logic clean of print statements.
classDiagram
class Book {
-String id
-String title
-int stock
+getId()
+setStock()
}
class Library {
-ArrayList~Book~ books
-static int totalBooks
+addBook(Book)
+lendBook(String id)
+searchBook(String id)
}
class LibraryApp {
-Library library
-Scanner scanner
+start()
-showMenu()
-handleOptions()
}
LibraryApp --> Library : uses
Library o-- Book : manages
- Inventory Management: Dynamic addition of books using ArrayList.
- Stock Tracking: Real-time updates to global book counts using static properties.
- Lending System: Logic to decrease stock upon lending and validate availability.
- Search: ID-based lookup algorithms.
- Encapsulation: All class attributes are private; access is controlled via methods.
- Polymorphism: Overriding the toString() method for clean object visualization.
- State Management: Using static to maintain counters across the application lifecycle.
- Input Handling: Robust use of java.util.Scanner for interactive menus.
- Clone the repository:
git clone https://github.com/huderdcv/java-oop-library-system.git- Compile the source:
javac library/*.java- Run the Main class:
java library.Main