123456789101112131415161718192021222324252627282930
  1. import java.util.*;
  2. /**
  3. * Write a description of class Inventory here.
  4. *
  5. * @author (your name)
  6. * @version (a version number or a date)
  7. */
  8. public class Inventory
  9. {
  10. List<Product> productList = new ArrayList<Product>();
  11. public void addProductToInventory(Product product)
  12. {
  13. productList.add(product);
  14. }
  15. public Product[] getInventory(){
  16. return this.productList.toArray(new Product[productList.size()]);
  17. }
  18. public double sumInventoryValue(){
  19. double sum = 0;
  20. for (Product p : this.productList){
  21. sum += p.getPrice()*p.getQuantity();
  22. }
  23. return sum;
  24. }
  25. }