8) Problems
Last updated
Last updated
Create a class Book with id, name as the member variables.
Create BookNotFoundException as a checked exception and create one argument constructor which is accepting String message.
Create a test class with an array of 5 book with ids starting from 1.
Create a method findById(Book[] books , int id) which will take the previously created book array and and one id to find the book.
Print "Found" if the book is present with the given id else throw BookNotFoundException with a message "Book with the given id is not present".
Handle the exception in main method and print the stacktrace in catch block.