I have to create an arraylist of Shops objects which have a name, description and another arraylist of products objects. The addProduct method is left blank because this is where I face a problem. I need to select a specific shop name in the shop arraylist created with Shops objects and then add one or more products in the arraylist of products. I don't understand how I can manage to do that. If you guys could help me.
This is the code I have so far:
//class of shops but I removed the getters and setters to keep the code short
public class Shops {
private String name;
private String desc;
private ArrayList<Products> product;
public Shops(String name, String desc, ArrayList<Products> product) {
this.name = name;
this.desc = desc;
this.product = product;
}
//another class called Shop assistant which adds products to a specific shop
public class ShopAssistant {
ArrayList<Shops> shop = new ArrayList<>();
public void addShops(Shops shop) {
shop.add(shop);
}
public void addProduct(Products product ) {
//add products to product arraylist which should be linked to shop arraylist
}