Programming Challenge: Library Inventory System

Written by

in

Build a console-based application utilizing OOP, Collections, and Exception Handling.

Tasks:

  1. Create a Book class with fields for id, title, author, and stockCount. Include proper encapsulation (private fields, public getters/setters).
  2. Create a custom exception class named OutOfStockException that extends Exception.
  3. Create a Library class that uses a HashMap<Integer, Book> to store the inventory (where the key is the book ID).
  4. Implement a method borrowBook(int id) in the Library class. If the book’s stockCount is 0, throw the OutOfStockException. If it is available, reduce the stock by 1.
  5. Create a Main class to populate the collection with 3 books and simulate a borrowing process that eventually triggers your custom exception.

Comments

Post your Comment About This Product

Your email address will not be published. Required fields are marked *