Hi, I am doing some blueJ work but am not the best at it. I have to create a basic library system, this is made up of three classes. Book, Member and Library.

These are the following requirements for my library class:

1.It has two fields of ArrayList: one is to store a collection of books; the other is to store a list of members.

2.The class constructor method take no parameter; it initialises each field with an empty list.

3.It has a method to add a new member into the list of members.

4.It provides a method to add a new book into the book collection.

5.It provides a method to print the details of all books in the library.

6.It has a method that takes an author's name and returns nothing. It prints out the titles of all books by the given author.

7.It has a method that takes a Book object and returns the number of copies of the given book in the library.
Note: two books are the same if they have the same title and author.

8.It provides a method for a member to return a book. It takes an object of Member and an object of Book and returns nothing.

9.It has a method for a member to borrow a book with the given title and author. It takes three parameters: an object of Member and two strings, title and author of a book. It checks, before the member is allowed to borrow the book, if the given book is in the collection and available. If so, it returns the book borrowed by the member, otherwise it returns null.

10.It provides a method to print the member's ID and the number of books borrowed by each member. Members who have not borrowed any books should not be displayed.

I think I have done 1-4 correctly but I was trying to test this by implementing the print methods and this is where I have become stuck. Any help of information is much appreciated.

This is the library class:

/**
* Write a description of class Liabrary here.
*
* @jdm37
* @v1.0
*/
import java.util.ArrayList;


public class Liabrary
{
//Storage for books and members
private ArrayList<Book> books;
private ArrayList<Member> members;



public void addBook(Book nbook)
{
books = new ArrayList<Book>();
books.add(nbook);
}


public void addMember(Member nmember)
{
members = new ArrayList<Member>();
members.add(nmember);


}



public void printMember(String Member)
{
System.out.println("ID: " + id + " Name: " + name);
}
}

Edited 3 Years Ago by Nick Evan: Fixed formatting

You'll need a "main" method somewhere - that's the one that is run when your application starts. In that method you can create a new library, add books and members, and call your print method(s) to see if it's all working.
And you'll need at least some code for your Book and Member classes.

ps: in Library, are you sure you want to create a new ArrayList of books every time you add a book?

Thanks for the quick reply. I sorted the printing of the books added to the library it was just me being silly over looking it. I have code in all the classes now as well. Would it be best for me to upload all the code?

This article has been dead for over six months. Start a new discussion instead.