Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- class ProductList {
- List<Product> products;
- ProductList()
- {
- products = new ArrayList<Product>();
- }
- void add(Product p)
- {
- products.add(p);
- }
- void set(int index, Product p)
- {
- products.set(index, p);
- }
- void clear()
- {
- products.clear();
- }
- void remove(int index)
- {
- products.remove(index);
- }
- void remove(Product p)
- {
- products.remove(p);
- }
- Product get(int index)
- {
- return (Product)products.get(index);
- }
- int getTotalInventory()
- {
- int inventory = 0;
- for(int i = 0; i < products.size(); i++) {
- Product pp = products.get(i);
- if(pp != null) {
- inventory += pp.getInventory();
- }
- }
- return inventory;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment