Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java- Piece of Book Rental/Library Program In BookMarket.java. Create a method named printBookOptions that has an array of objects as parameter and returns an integer.

Java- Piece of Book Rental/Library Program

  1. In BookMarket.java. Create a method named printBookOptions that has an array of objects as parameter and returns an integer. This method will help select a book and return its id and will be useful in selecting a book. Since the id is set as the index of the array, it is convenient for us.

Using a loop, print Enter index for bookname for each of the 4 books, where index is the id of the book and bookname is the name of the book.

If a user enters an invalid integer, you must ask the question again.

Here is a very helpful hint: Do not use nextInt(), use nextLine() and convert it to integer using Integer.parseInt(input.nextLine()).

Finally return the valid choice of the user, which is the id of the selected book.

  1. Create a method rentABook which has a parameter of a book object and returns nothing.

This method will try to rent a book using the rentBook method of Class Book. But make sure that you check if the book is available to rent, if the book is not available print Book not available. Hint check if object.rentBook() returns -1 or not.

The book will be rented for a certain number of days. Ask the user how many days they want to rent. If the number of days is less than 1, you need to keep asking. (Hint: use a while loop)

After getting a valid date, use setRentDays method from Class Book to set days rented.

At the same time, update your balance, multiply the number of days with rent amount of that book.

  1. Create a method named returnABook which has two parameters and does not return anything. The first parameter is an array of objects of class Book and second is an integer that represent the id of the book.

For that id, return the book using the method returnBook of Class Book.

  1. The main method will provide the options to rent or return the book. This option will be presented in a loop. Here is the option: Do you want to rent(ren) or return(ret) or edit (edit)a book ? quit to exit

For now replace the print lines from the options as

If the user enters ren,

Use the method printBookOptions to get the id of the book to rent

Use the method rentABook to rent the book

Use the method printInventory to display the inventory

If the user enters ret,

Use the method printBookOptions to get the id of the book to return

Use the method renturnABook to renturn the book

Use the method printInventory to display the inventory

If the user enters quit,

Print Quitting the program....

End the loop and end the program

If a user enters anything else,

Print Invalid choice.

And display the menu again.

-Use a do while loop.

5. Create a method named replaceBook which has a parameter of an array of objects of class Book, integer id of book and return an object of type Book.

Ask the user to enter the new book title,and save it to a string.

Ask the user to enter the new book price and save it to a double. (Hint: Use Double.parseDouble(input.nextLine()) instead of input.nextDouble())

Create an object of this new book (use the integer id).

Reduce the static variable count by one of the class Book. (We do this since the constructor always increase the count by one, but we are not increasing the books, we are replacing it, so the count is same)

Return this new book

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 Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions

Question

1.what is the significance of Taxonomy ?

Answered: 1 week ago

Question

What are the advantages and disadvantages of leasing ?

Answered: 1 week ago

Question

Name is needed for identifying organisms ?

Answered: 1 week ago