8) Problems

Problem :

1)

Do the following:

  1. Create a class Book with id, name as the member variables.

  2. Create BookNotFoundException as a checked exception and create one argument constructor which is accepting String message.

  3. Create a test class with an array of 5 book with ids starting from 1.

  4. Create a method findById(Book[] books , int id) which will take the previously created book array and and one id to find the book.

  5. 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".

  6. Handle the exception in main method and print the stacktrace in catch block.

Coding Problem :

Quiz :

Last updated