import java.util.*; import javax.swing.*; public class Library { int id; String date; String description; int copies; String title; int bookCount; int magCount; int multiCount; ArrayList<Book> newBook = new ArrayList<Book>(); ArrayList<Magazine> newMag = new ArrayList<Magazine>(); ArrayList<Multimedia> newMulti = new ArrayList<Multimedia>(); ArrayList<Library> newLib = new ArrayList<Library>(); public void addItem(int newId, String newDate, String newDesc, int newCopies, String newTitle, String newAuthor, String newPub, int newIsbn) { for(int x = 0; x < newBook.size(); x++) { bookCount++; // I'am having trouble here in adding book object to my arraylist. newBook.get(x) = new Book(); newBook.get(x).setId(newId); newBook.get(x).setDate(newDate); newBook.get(x).setDescription(newDesc); newBook.get(x).setCopies(newCopies); newBook.get(x).setTitle(newTitle); newBook.get(x).setAuthor(newAuthor); newBook.get(x).setPublisher(newPub); newBook.get(x).setIsbn(newIsbn); } } // and i think this method does not work because it cannot retrieve anything, because my addItem method isn't working public void retrieveItem(int id) { for(int x = 0; x < bookCount; x++) { if(id == newBook.get(x).getID()) { JOptionPane.showMessageDialog(null, "Book Title: " + newBook.get(x).getTitle() + "\nBook Author: " + newBook.get(x).getAuthor() + "\nBook Publisher: " + newBook.get(x).getPublisher() + "\nBook ID: " + newBook.get(x).getID() + "\nBook ISBN: " + newBook.get(x).getIsbn() + "\nDate Acquired: " + newBook.get(x).getDate() + "\nNumber of Copies: " + newBook.get(x).getCopies() + "\nDescription: " + newBook.get(x).getDescription()); } else { JOptionPane.showMessageDialog(null, "NOT FOUND"); } } } public void setId(int temp) { id = temp; } public int getID() { return id; } public void setDate(String temp) { date = temp; } public String getDate() { return date; } public void setDescription(String temp) { description = temp; } public String getDescription() { return description; } public void setCopies(int temp) { copies = temp; } public int getCopies() { return copies; } public void setTitle(String temp) { title = temp; } public String getTitle() { return title; } }
please help me out here. i added some comments in the code where im having trouble.