Question: Develop an inventory management system for a store using a custom exception OutOfStockException to handle insufficient stock errors on orders. Instructions: 2 . Creating the

Develop an inventory management system for a store using a custom
exception OutOfStockException to handle insufficient stock errors on orders.
Instructions:
2. Creating the OutOfStockException class:
o Define an OutOfStockException class that inherits from Exception.
o Add a constructor that takes a message as a parameter to specify the reason of the
exception.
3. Creating the checkStock method:
o Create a checkStock(int available, int requested) method that checks
whether the requested quantity is available.
o If the requested quantity exceeds the available stock, throw
the OutOfStockException with an appropriate message.
4. Writing the main program :
o Write a main program that simulates a situation where the user tries to order more
products than the available stock.
o Call the checkStock method with the quantities available and requested.
o Catch the OutOfStockException and display the error message if an exception
is thrown.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!