Question
If you could help with this Java assignment that would be great, Thank you! CSCI 2540 Assignment 4 100 points Due date: Tuesday, Feb. 12
If you could help with this Java assignment that would be great, Thank you!
CSCI 2540 Assignment 4 100 points Due date: Tuesday, Feb. 12 (before class)
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
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:
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
Enter book id: 10001
Book id: 10001, Title: Emma, ISBN: 0486406482, Author: Austen, Fiction
Enter book id: 0
Note: if you use Eclipse, the input file should be placed outside of src folder.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started