/* Comp1100 Sem 1, 2006
 * 
 * Supermarket Docket Example Program
 * 
 * DB class represents database of supermarket products.
 * The structure is a simple unordered list of products.
 * Search is a simple linear search on barcodes.
 *
 * Clem Baker-Finch May 2006
*/

import java.util.ArrayList;

class DB {

    private ArrayList<Product> database;

    // Construct a new empty database
    public DB() {
	database = new ArrayList<Product>();
    }

    // Add a product to the database
    public void add(Product product) {
	database.add(product);
    }

    // Given a barcode, find the product in the database
    // If not present, return a dummy product
    public Product find(Integer barcode) {
	for (Product item: database) {
	    if (item.getBarcode().equals(barcode))
		return item;
	}
	return new Product(0, "Unknown item", 0);
    }

}


