📄 catalog.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -