Inventory.java 870B

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * Write a description of class Inventory here.
  3. *
  4. * @author (your name)
  5. * @version (a version number or a date)
  6. */
  7. import java.util.ArrayList;
  8. public class Inventory {
  9. ArrayList<Product> products = new ArrayList<Product>();
  10. private static double totalValue;
  11. private static int totalQuantity;
  12. public double getTotalValue() {
  13. return totalValue;
  14. }
  15. public int getTotalQuantity() {
  16. return totalQuantity;
  17. }
  18. public void addToInventory(Product fresh) {
  19. products.add(fresh);
  20. totalValue += (fresh.getPrice() * fresh.getQuantity());
  21. totalQuantity += fresh.getQuantity();
  22. }
  23. public void removeFromInventory(Product old) {
  24. products.remove(old);
  25. totalValue -= (old.getPrice() * old.getQuantity());
  26. totalQuantity -= old.getQuantity();
  27. }
  28. }