Question

A bookstore owner wants to maintain information about all the books in stock.

Design, write in Java, test and document a program which must have at least two class definitions:

  • A book class which can be used to represent the details of a book together with some associated operations, and
  • A client class of the book class

The book class will have data members described as follows, which should be declared as private:

(a) Title of the book - a string of characters
(b) Name of the first author (surname followed by first name or initial) - a string of characters
(c) Publisher a string of characters
(d) Year of publication an integer
(e) ISBN a long integer
(f) Price a float or double
(g) Number of copies in stock (quantity) an integer

Include the member methods to perform the various operations on the objects of book class. For example, the usual operations that can be performed on the title are to get the title and to set the title. Similarly, the typical operations that can be performed on the number of copies in stock are to get the number of copies in stock, set the number of copies in stock, and update the number of copies in stock (i.e. increase the quantity of existing stock). Add similar operations for the publisher, year of publication, ISBN, book price, and author. The book class will have at least the following constructors and methods:

(i) two constructors - one without any parameters (the default constructor), and one with parameters to give initial values to instance variables. The parameters should be in the following order - Title, Author, Publisher, Year, ISBN, Price and InStock

(ii) a reasonable number of set, get and update methods to perform the various operations as explained in the above paragraph

(iii) one or more input methods to get user input from the keyboard and one or more output methods to print out book information in an appropriate format.

(iv) a method which calculates and returns the total value (in dollar terms) of a particular title (book) in stock

(v) an equals method which compares two book objects and returns true if they have the same title, the same author and the same ISBN

You may add other methods as you see appropriate. However, you will need to document them clearly.

The program will allow entry of these data for several books and perform some analysis and queries.

Your program will provide the user with a menu which allows the following actions:

1. Quit

2. Create an array of N books. For each book, read in its details (i.e., title, name, publisher, year of publication, ISBN, price, and quantity in stock) from the keyboard, and store it in the array. Test it with N =

3. Output details (all information) of all books currently in stock;

4. View all information about a book chosen via its ISBN number. If the book is not in stock, an appropriate error message is to be displayed;

5. View all information about a book chosen via its author. If the book is not in stock, an appropriate error message is to be displayed. If there is more than one book by this author, the details of all those books should be displayed.

6. Given an ISBN, update the number of copies (quantity) of a book. If the book is not in stock, an appropriate error message is to be displayed;

7. Given the title of a book, update its price. If the book is not in stock, an appropriate error message is to be displayed;

8. Determine and display details of the most expensive book in stock;

9. Determine and display the quantity of total stock in the array (bookstore);

10. Determine and display the monetary value of total stock in the bookstore;

11. Add a new book to the array by creating an add method named addBook that takes as parameter a Book object and adds the Book object to the array. Note that this operation will increase the array size by 1.

12. Given a book's ISBN, delete/remove an existing book from the array. If the book is not found display an appropriate error message. Note that if delete is successful, it will reduce the array size by 1.

13. Using one of the sorting methods described in the lecture notes, sort the array of book objects into ascending (alphabetical/dictionary) order of their first authors, and output the sorted array.

Set up a bookstore (an array) of N book objects, and test it with N = 6. Note the initial array size should start as 1 element.

There is no requirement for the program to store data when the program quits. The interaction with the user is via a (command line) menu.

The client class should be well-structured and should have a reasonable number of methods in addition to the main method. Devise suitable test data to test all sections of program code.

Your program should also include a method (eg, StudentInfo( )) to output your student details (name, student number, mode of enrolment, tutor name, tutorial attendance day and time) at the start of program results.

Note: The question requires you to use an array and not any Java library class to store details of books. Also, the sorting algorithm used must be coded within your program and not called from any Java libraries.

Suggested Design:

You should at least have a book class and a client class which works with an array of books. You need to think carefully about which tasks can be dealt with just inside the book class and which tasks involve the whole array of books.

Whichever, overall design you use, most of the work will then be in getting the algorithm right inside the methods and catering for the convenience of the user.

For internal documentation (ie in the source code) we require:

  • a beginning comment clearly stating title, author, date, file name, purpose and any assumptions or conditions on the form of input and expected output;
  • other comments giving useful low-level documentation and describing each component;
  • well-formatted readable code with meaningful identifier names and blank lines between components (like methods and classes).
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.