Question

So here's what I am doing. I create a book, I add the book to an inventory class that extends an inventory of overall products (contains the arraylist for the program) with this:

    myBookInventory.addProduct(myBook);

Which comes from:

    super.addProduct(pBook); // From BookInventory class that extends ProductInventory class

Which contains the following code:

     public void addProduct(Product pProduct)
{

    // Add the new product to the product inventory array list
    myProductInventory.add(pProduct);


}

ProductInventory has an arraylist called myProductInventory. What I want to do is display the information of that product. Here's what I use:

    for (Product product: productList.myProductInventory) {
                System.out.println(product);
            }

Problem occurs here in this System.out. It does not display anything, and I have no idea why. I'm open to any solution. If there's anything missing that you'd like for me to show you, just let me know.

Was it helpful?

Solution

It looks like new books are added to InventoryProgram's myBookInventory, but you are displaying books from Menu's productList, which is still empty.

OTHER TIPS

From user3108443L:

" I did the following:

for (int i = 0; i < myBookInventory.getSize(); i++) {
            System.out.println(myBookInventory.getProduct(i));
        }

This printed out exactly what I wanted. "

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top