i am trying to store an object in an arraylist from one class(LibraryItem) in another class (Library). But i am having some issues when i try to store the object in the arraylist.
The Library class needs to store the LibraryItem in an array list and print all of the items that are stored in it
code for LibraryItem
public class LibraryItem
{
private String title;
private String itemCode;
private int cost;
private int timesBorrowed;
private boolean onLoan;
/**
* Constructor for objects of class LibraryItem
*/
public LibraryItem(String title, String itemCode, int cost, int timesBorrowed, boolean onLoan)
{
// initialise instance variables
this.title = title;
this.itemCode = itemCode;
this.cost = cost;
this.timesBorrowed = timesBorrowed;
this.onLoan = onLoan;
```
**code for Libray**
```
public class Library
{
// instance variables - replace the example below with your own
private ArrayList<LibraryItem> itemList;
/**
* Constructor for objects of class Library
*/
public Library()
{
// initialise instance variables
itemList = new ArrayList<LibraryItem>();
}
public void storeItem(LibraryItem libraryItem){
itemList.add(libraryItem);
}
public void printAllItems(){
for (LibraryItem ob : itemList){
System.out.println("The Library item ");
System.out.println("Title: "+ ob.getTitle());
System.out.println("Code: "+ ob.getItemCode());
System.out.println("Code: "+ ob.getCost());
System.out.println("Code: "+ ob.getTimesBorrowed());
System.out.println("Code: "+ ob.getOnLoan());
System.out.println("-----------------------------------");
}
}
}