CSCI 180 (GOLDWEBER)
Spring 07: 2/07/07
Laboratory 4: Object Collections and Iterators
Due Date: Monday February 12, 2007.
A company records stock levels of the products it sells. A StockManager object maintains an arbitrary-length list of Product objects. Your task is to implement the StockManager class.
The StockDemo class has also been provided to help demonstrate ways in which StockManager and Product objects might be used. You can create a StockDemo object on the object bench and call its demo method. As you develop the StockManager class, this demo should demonstrate increasing functionality.
All three classes, Product, StockDemo, and a skeleton for StockManager are in the Chapter 4 class projects directory.
The StockManager class
This class uses an ArrayList object to store zero or more Product items.
In addition to a parameterless constructor you should implement:
  1. addProduct: Add a new product to the collection being managed by the StockManager. This void method takes one parameter of type Product.
  2. printProductDetails: Iterate over the list of products and print the result of calling the toString() method on each.
  3. printLowStockProductDetails: Print the details of all products with stock levels below a given value (passed as a parameter to the method).
  4. delivery: Look through the collection for a product whose ID matches the id parameter of this method. If a matching product is found, invoke the increaseQuantity method on that object. The second input parameter is the amount the stock of that product should be increased by.
  5. findProduct Look through the collection for a product whose ID matches the id parameter of this method. If a matching product is found, that Product should be returned as the method's result. If no matching product is found return null from the method.
  6. findProduct Look through the collection for a product whose name matches the name parameter of this method. If a matching product is found, that Product should be returned as the method's result. If no matching product is found return null from the method.
  7. numberInStock: Look through the collection for a product whose ID matches the id parameter of this method. If a matching product is found return the current quantity of that product as the method's result. If no product with a matching ID is found, return zero.
  8. removeProduct: Look through the collection for a product whose ID matches the id parameter of this method. If a matching product is found, remove it from the collection and return that Product as the method's result. If no matching product is found return null from the method.
  9. Modify the addProduct method so that a new product cannot be added to the product list with the same ID as an existing one. Generate an appropriate message if an attempt to add a product with the same ID as an existing one.



File translated from TEX by TTH, version 3.74.
On 7 Feb 2007, 14:18.