Question: JAVA so basically i have an array of BookStock named BookShelf, and i need to get this method to addOrUpdate a book in the bookshelf,

JAVA so basically i have an array of BookStock named BookShelf, and i need to get this method to addOrUpdate a book in the bookshelf, or if the book already exists there, I need to Update its quantity. The Method header must be exactly public void addOrUpdateBookStock(Book book, float quantity) as per the assignment.

public void addOrUpdateBookStock(Book book, float quantity){ BookStock x = new BookStock (book.getName(), book.getAuthor(), quantity);

for (int i = 0; i < BookShelf.size(); i++){ if (BookShelf.get(i).getName().equals(x.getName())){ BookShelf.get(i).setQuantity(quantity); } else { BookShelf.add(x); } }

The problem is: when i try to test it, nothing is getting added into the array!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!