Few designs flaws... you will have to decide how to proceed
I assume status describes if a book is borrowed or not ... and there is only one status for each book
as you have only 1 borrowedDate.
Your BookManager is keeping only one entry for every book... now if you have 15 Robinson Crusoe how eill you distinguish between the one borrowed and the one not borrowed ?
When you add a book, you increment the count of the book you already have but your object Book pass as parameter is lost. So your BookManager would neeed a 2 dimensional array: [1000][10] to hold up to 10 copies of 1000 different books... not a really good design
Your getBook() method is useless... you receive a Book as parameter and you return the same book..
You do not need a Library class that is what it is your BookManager
You do not need a BorrowManager, the BookManager can do that
Honestly, forget about storing all the book with the same ISBN in the same slot just append them to your list. You can deal with that problem later.
You will need a
public int NumBooks=0;
in your BookManager to keep how many slots are used in your array of Books
Here is a modified version of your code... for simplicity I just kept: ISBN, Title and if borrowed
I add the main method in BookManager to test the code:
CODE
public class Book{
public String isbn;
private String title;
private boolean borrowed;
public Book (String isb, String tit){
isbn=isb;
title=tit;
borrowed = false; // new surely not borrowed
}
public String GetIsbn(){
return isbn;
}
public boolean isBorrowed(){
return borrowed;
}
public void setBorrowed(boolean status) {
borrowed = status;
}
public String GetTitle(){
return title;
}
public String toString(){
String str;
str = "Isbn:" +isbn+ " Title:" +title+ " Borrowed:" + borrowed;
return str;
}//end String
}
CODE
public class BookManager {
private static final int Max = 1000;
private Book[]bookList= new Book[Max];
public int NumBooks=0;
// add a book
public void addBook (Book i){
bookList[NumBooks++] = i;
}//end addBook
// borrow a book
public Book borrowBook(String isbn) {
for(int i = 0; i < NumBooks; i++) {
if(bookList[i].GetIsbn().equalsIgnoreCase(isbn))
{
if(bookList[i].isBorrowed() == false) {
bookList[i].setBorrowed(true);
return bookList[i];
}
}
}
// book not found or all borrowed
return null;
}
// return a book
public void returnBook(Book b) {
for(int i = 0; i < NumBooks; i++) {
if(bookList[i] == b)
{
bookList[i].setBorrowed(false);
break;
}
}
}
// list all books
public String toString() {
String str = "";
for(int i = 0; i < NumBooks; i++) {
str = str + "\n" + (i+1) + ") " + bookList[i].toString();
}
return str;
}
public static void main(String[] arg) {
BookManager bm = new BookManager();
Book book1 = new Book("1234-5678", "My Life");
Book book2 = new Book("1111-2222", "My wife");
Book book3 = new Book("3333-4444", "My Dog");
bm.addBook(book1);
bm.addBook(book2);
bm.addBook(book3);
System.out.println("Library listing: " + bm);
// try to borrow a book
Book b = bm.borrowBook("1111-2222");
System.out.println("Book borrowed: " + b);
System.out.println("Updated book list: " + bm);
}
}