Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

📚 Library Management System

A console-based Java application demonstrating Exception Handling, Object-Oriented Programming, and Collections through a simple library management system.

Java Concept Status


📌 Overview

This project implements a basic library system where users can add, list, borrow, and return books. The core focus of this implementation is to demonstrate how to create and handle Custom Exceptions to manage invalid states and business logic errors gracefully.


✨ Key Features

Category Feature Description
📖 Book Management Validation Ensures books have valid titles and positive page counts
🏛️ Library Operations Add & List Add books to the library and display the inventory
Borrow & Return Simulate borrowing and returning books by title
⚠️ Exception Handling Custom Exceptions Tailored exceptions for specific library errors
Try-Catch Blocks Robust error handling in the main execution flow

🚨 Custom Exceptions

Exception Class Trigger Condition
InvalidBookException Thrown when trying to add a null book to the library
EmptyLibraryException Thrown when listing books or borrowing from an empty library
BookNotFoundException Thrown when trying to borrow/return a book that doesn't exist
IllegalArgumentException Thrown when creating a book with invalid title or page count

📁 Project Structure

File Type Responsibility
Book.java Entity Represents a book with title and page count validation
Library.java Manager Handles book collection, borrowing, and returning logic
BookNotFoundException.java Exception Custom exception for missing books
EmptyLibraryException.java Exception Custom exception for empty library state
InvalidBookException.java Exception Custom exception for invalid book objects
Main.java Entry Point Demonstrates the system workflow and exception handling

🚀 Quick Start

1. Compile

Ensure all files are in the Management package directory, then compile:

javac Management/*.java

2. Run

java Management.Main

(Or run Main.java directly from your IDE)


💻 Usage Example

Library library = new Library();

try {
    // Add a valid book
    Book book = new Book("Clean Code", 400);
    library.addBook(book);
    
    // Borrow the book
    library.borrowBook("Clean Code");
    
} catch (InvalidBookException | BookNotFoundException e) {
    System.out.println("Error: " + e.getMessage());
}

📊 Sample Output

Library is empty
Title cannot be empty
Page count must be positive
Book should not be null.
Book should not be null.
Books in Library :
Clean Code(400pages)
this book (Clean Code(400pages)) has been successfully loaned
return Cannot. title with Book Clean Code not found
this book (Clean Code(400pages)) has been successfully returned


📝 License

This project is created for educational purposes to demonstrate Java Exception Handling concepts.


Built with ☕ Java & 🛡️ Custom Exceptions

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages