Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, you will write a program to simulate an inquiry system of a small library. The program should operate as follows: 1. Read

In this assignment, you will write a program to simulate an inquiry system of a small library. The program should operate as follows:

1. Read the library catalog from an input data file. The data file should be named catalog.txt. There is one input line per book, and these lines have the following format: where is a 5-digit positive integer (you may assume the leftmost digit is not a zero), is a string of at most 30 characters with no embedded blanks (you can use _ in between words in a title), is a string of 10 digits, is a string of at most 10 characters, and is a character (F if the book is fiction; N if it is a nonfiction book). You may assume the catalog has no more than 100 books (a small library). A sample catalog is shown at the end of the specification. Make sure to include exception handling code related to file input.

2. Read from standard input a customers inquiry with a given book_id and output the complete information of the book. Your program should allow the customer to continue to inquiry about other books. When a zero input for is entered, it means the end of the customers inquiry. The output should include the book_id, book_title, ISBN, author_last_name, and Fiction or Non-Fiction for category, printed on a single line. A sample output is shown at the end of the specification.

3. Exception handling: The following error is possible and should be handled by your program: not found. You need to define a BookNotFoundException and handle it by writing an error message. This should be defined as a checked exception. It should include two constructors. One is the default constructor, and the other is one-parameter constructor and the parameter type is String. Program Structure: Your source code should be developed in three files: Book.java, BookDemo.java, and BookNotFoundException.java. Book.java will contain the class definition for a book according to the requirements specified below. BookDemo.java will be the application program that runs the simulation of the inquiry. BookNotFoundException.java will define the checked exception.

Data Structure: Each catalog item should be an object of the Book class. Define a separate instance variable of the appropriate type for the five pieces of information about each book. Instance variables should be maintained as private data. Besides constructor(s), the following methods are required for the Book class.

A getter method for each instance variable.

A toString method that takes no parameter and returns all the information of the book as a combined string, including book_id, book_title, ISBN, author_last_name, and Fiction or Non-Fiction for category.

A static method bookSearch that takes three input parameters: (1) an array of Book objects that represent the entire catalog; (2) an integer specifying how many books are actually in the array; and (3) an integer representing a book_id. The method should search the array of books looking for the book with the given book_id as specified by the third parameter. The method should return the index within the array. If it cannot find the item, the method should throw a BookNotFoundException but it is not handled in this method. Instead it will be handled in the main method where it is called.

Sample Catalog file:

10001 Emma 0486406482 Austen F

12345 My_Life 0451526554 Johnson N

Sample interaction:

Enter book id: 12345

Book id: 12345, Title: My_Life, ISBN: 0451526554, Author: Johnson, Non-fiction

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

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago