With the code I currently have the number of loaned out books won't update, so for example if there are 20 books in the array. If 3 are loaned out, obviously the count goes to 3, but if these are returned the count seems to stay at 3. So if another book is loaned out, instead of loanedBookCount()
returning 1, it will return 4. Essentially what I seem to have is a method that counts the loaned book transactions.
This is not what I want, I want a method to count the number of books that are currently on loan at that time.
public int loanedBookCount(){
count = 0;
for(Book bkObj: bookStore){
if(bkObj.getCurrentStatus()== CurrentStatus.LOANED){
count++;
}
}
return count;
}
I have read through this link and this one but can't seem to find how to properly count every single occurrence.
It seems almost like finds the first one it gets to, then increases the count, but I could be wrong and the issue is something else. Either way, can anyone help me try to search for every single book object that is currently loaned out?
I have a method to return the books, but don't think this should include a way to update the number of books on loan (it is in a difference class for staters), I feel like this should a easy enough thing to do from searching the arraylist each time.
I should point out that in the main method uses a for
loop to simulate the transactions such as loaning and returning books.
edit: method to return books as requested:
//The aim of this method is to update the status, not create or remove objects
//if there are reservations the book is immediately loaned out,
//or set to available again if no reservations
public class Book{
...
public void returnBook(){
if(numberOfReservations ==0){
status.equals(CurrentStatus.AVAILABLE);
}
else{
status.equals(CurrentStatus.LOANED);
numberOfReservations--;