I am testing my Library class and the addItem method is not adding an item to the arraylist
import java.util.ArrayList;
public class Library {
/**
* itemList contains the List of all items in the library.
*/
private ArrayList<Item> itemList = new ArrayList<Item>();
Item item = new Item();
// Empty Constructor
public Library(){}
/**
* Add a new item to the list of library items.
* @param newItem The new item to be added to the list.
*/
public void addItem(Item newItem)
{
itemList.add(newItem);
}
The testDriver has this method
Library str = new Library();
ArrayList itemList = new ArrayList();
Item item = new Item();
Item cd = new MusicCD("id002", "Best of Police", false, null, 5.50, "Sting", "Sting");
str.addItem(cd);
str.loanItem("id002", null);
When I ask it to display the arraylist itemList it has nothing in it
System.out.println(itemList.size());
I am not sure where I am going wrong here?