Build a console-based application utilizing OOP, Collections, and Exception Handling.
Tasks:
- Create a
Bookclass with fields forid,title,author, andstockCount. Include proper encapsulation (private fields, public getters/setters). - Create a custom exception class named
OutOfStockExceptionthat extendsException. - Create a
Libraryclass that uses aHashMap<Integer, Book>to store the inventory (where the key is the book ID). - Implement a method
borrowBook(int id)in theLibraryclass. If the book’sstockCountis 0, throw theOutOfStockException. If it is available, reduce the stock by 1. - Create a
Mainclass to populate the collection with 3 books and simulate a borrowing process that eventually triggers your custom exception.
Post your Comment About This Product