12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
-
- import java.util.Hashtable;
- import java.util.Set;
-
- /**
- * Write a description of class Inventory here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class Inventory
- {
- Hashtable<String, Product> productInventory;
-
- public Inventory() {
- productInventory = new Hashtable<String, Product>();
- }
-
- public void addItem(Product prod) {
- productInventory.put(prod.getID(), prod);
- }
-
- public void addItem(float price, int quantity, String id) {
- Product newItem = new Product(price, quantity, id);
- productInventory.put(id, newItem);
- }
-
- public Product getItem(String id) {
- return productInventory.get(id);
- }
- public int getOnHandQuantity(String id) {
- return productInventory.get(id).getOnHandQuantity() ;
- }
- public float getPrice(String id) {
- return productInventory.get(id).getPrice();
- }
-
- public void updatePrice(String id, float price) {
- productInventory.get(id).setPrice(price);
- }
-
- public void addUnits(String id, int quantity) {
- productInventory.get(id).addUnits(quantity);
- }
-
- public void removeUnits(String id, int quantity) {
- productInventory.get(id).removeUnits(quantity);
- }
-
- public double getInventoryValue() {
- double inventoryValue = 0;
- Set<String> productIDs = productInventory.keySet();
-
- for (String id : productIDs) {
- Product p = productInventory.get(id);
- int quantity = p.getOnHandQuantity();
- float price = p.getPrice();
- inventoryValue += quantity * price;
- }
-
- return inventoryValue;
- }
- }
|