Inventory.java 819B

12345678910111213141516171819202122232425262728293031
  1. import java.util.ArrayList;
  2. public class Inventory
  3. {
  4. private ArrayList<Product> products;
  5. public Inventory(){
  6. products = new ArrayList<>();;
  7. }
  8. public void add(Product product){
  9. products.add(product);
  10. }
  11. public String getAllProductInfo(){
  12. String info = "";
  13. for (Product element: products){
  14. info += "Product: " + element.getName() + "\nProduct ID: " + element.getId() + "\nPrice: " + element.getPrice() + "\nQuantity: " + element.getQuantity() + "\nValue: " + element.getValue() + "\n****************\n";
  15. }
  16. return info;
  17. }
  18. public double getTotalInventoryValue(){
  19. double total = 0;
  20. for(Product element: products){
  21. total += element.getValue();
  22. }
  23. return total;
  24. }
  25. }