catalog.java

来自「ssd3 exercise4正确的」· Java 代码 · 共 81 行

JAVA
81
字号
import  java.util.*;
import java.io.*;


public class Catalog  
{

	/* Collection of <code>Product</code> objects.*/
	private Vector  products;

	/**
	 * Constructs an empty catalog.
	 */
	public Catalog() 
	{

		products = new Vector();
	}

	/**
	 * Adds a {@link Product} object to this catalog.
	 *
	 * @param product  the {@link Product} object.
	 */
	public void  addProduct(Product product)  
	{

		products.add(product);
	}

	/**
	 * Returns an iterator over the products in this catalog.
	 *
	 * return  an {@link Iterator}
	 */
	public Iterator  getProductsIterator() 
	{

		return products.iterator();
	}

	/**
	 * Returns the {@link Product} object with the specified
	 * <code>code</code>. 
	 *
	 * @param code  the code of a product.
	 * @return  The {@link CatalogItem} object with the specifed
	 *          code. Returns <code>null</code> if the object with
	 *          the code is not found.
	 */
	public Product  getProduct(String code)  
	{

		for (Iterator i = getProductsIterator(); i.hasNext();) 
		{

			Product product = (Product) i.next();

			if (product.getCode().equals(code)) 
			{

				return product;
			}
		}

		return null;
	}

	/**
	 * Returns the number of products in the catalog.
	 *
	 * @return the number of {@link Product} objects in this
	 *         catalog 
	 */
	public int  getNumberOfProducts()  
	{

		return products.size();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?