Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CODE IN JAVA Consider the Book class and BookService interfaces given below. 1. Define constructor of Book class (inside the Book class code given above),

CODE IN JAVA Consider the Book class and BookService interfaces given below.

1. Define constructor of Book class (inside the Book class code given above), such that it shall take and intialize 'title' and 'available' fields. It shall auto assign a unique id to each book, starting from 1. (you can add new fields in below given Book class code, required to meet this requirement). [5 marks]

2. Create BookServiceImpl class that shall implement BookService interface. It shall implement all methods of the interface. All books should be stored in instance variable books of type ArrayList. When class is loaded, 3 books shall be automatically added in books collection. [5 Marks]

3. Define BookAlreadyExistException, BookNotFoundException, BookAlreadyIssuedException as checked exceptions. Each exception object shall also store the book ID. Define a constructor that takes and initialize book id and Override getMessage such that, it shall return the . [5 Marks]

4. Create a BookServiceTest class. In main method, call add, getBook and isseBook methods that shall handle the potential exceptions. It shall print the book id and exception name. No need to get data from user. Hard code whatever you need to call these methods. [5 Marks]

class Book { private int id; private String title; private boolean available; // true means, available in library. can be issued // define constructor here // assume all get/set are already defined }

public interface BookService {

// add method shall add the passed book, if book ID matches with existing books // it show throw BookAlreadyExistException void add(Book book) throws BookAlreadyExistException; // getBook shall return the book of ID passed in argument. or throw BookNotFoundException Book getBook(int bookID) throws BookNotFoundException; // isseBook shall set the book 'available' field to false. // it shall throw the BookAlreadyIssuedException if the 'available' field is already false boolean issueBook(int bookID) BookAlreadyIssuedException; }

// Define all exceptions classes here

// Define BookServiceImpl class here

// Define BookServiceTest here

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Write an NC program to cut a 0 . 2 5 jb - deep pocket on a 3

Answered: 1 week ago