⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 catalog.java

📁 这是我修读美国卡耐基梅隆大学Carnegie Mellon University(CMU)课程ssd3:Object-Oriented Programming and Design时完成的课程设计
💻 JAVA
字号:
import java.util.*;

/**
 * The class Catalog models a product catalog.It contains methods to process vectors of {@link Product} objects.
 *
 * @author  张维
 * @version  1.0.0
 * @see  Product
 * @see  Vector
 */
public class Catalog  {
 	
 	/* A vector that contains <code>Product</code> objects */
 	private Vector products;
 	      
  /**
   * Constructs an empty catalog.
   */
  public Catalog( ) {
        	 	  
 	   products = new Vector( );
  }
        	 
  /**
   * Adds the specified product to the catalog.
   *
 	 * @param product   a  <code>Product</code> object.
   */
  public void addProduct(Product product) {
        	
	   products.add(product);
  }
        
 	  
  /**
 	 * Returns an iterator over the instances in this catalog.
 	 *
 	 * @return  an {@link Iterator} over the instances in this catalog. 
   */
  public Iterator getProductsIterator( ) {
        	
     return products.iterator( );
  }
        
 	   	
  /**
 	 * Returns the <code>Product</code> object in the catalog with the specified <code>code<code>. 
 	 * Returns null if there are no products in the catalog with the specified <code>code</code>. 
 	 *
 	 * @param code  the code of an product.
 	 * @return  the <code>Product</code> object with the specified code.
   */
  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 <code>Product</code> objects in this catalog.
    */
   public int getNumberOfProducts( )  {
       	
 	   	 return products.size( );
   }
   
   /**
    * Returns an array of product codes (all the product codes in the product catalog),
    * which is used by GourmetCoffeeGUI to populate the catalog JList. 
    *
    * @return  an array of all the product codes in the product catalog
    */
   public String[ ] getCodes( ) {
       	
      String codesArray[ ] = new String[getNumberOfProducts( )];
      int i = 0;
      
      for(Iterator iterator = getProductsIterator( ); iterator.hasNext( );)
         codesArray[i++] = ((Product)iterator.next( )).getCode( );

        return codesArray;
    } 	   	  
 }

⌨️ 快捷键说明

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