// Import the java related classes used in the example.
import java.io.*;
import java.util.*;

public class CatalogItem {

  // Fields in the CatalogItem class.
  private Product theProduct = null;
  private int quantity;

  private int initialBufferLength = 64;
  private String productType = null;
  private String productName = null;

  // Constructor
  public CatalogItem(Product inProduct, int inQuantity) {
    theProduct = inProduct;
    quantity = inQuantity;
    setProductType(theProduct.getClass().getName());
    setProductName();
}

  public int getQuantity() {
    return quantity ;
  }

  public void setQuantity(int inQuantity) {
    quantity = inQuantity;
  }

  public Product getProduct() {
    return theProduct;
  }

  public String getName() {
    return theProduct.getName();
  }

  public void setProductName() {
    productName = getName();
  }

  public String getProductName() {
    return productName;
  }

  public void setProductType(String packageProductType) {
    String tmp = null;
    StringTokenizer strTokenizer = 
      new StringTokenizer(packageProductType, ".");
    while(strTokenizer.hasMoreTokens()) {
      tmp = strTokenizer.nextToken();
    }
    productType = tmp;
  }

  public String getProductType() {
    return productType;
  }

  public String toString() {
    StringBuffer productBuffer = new StringBuffer(initialBufferLength);
    productBuffer.append("CatalogItem=[Product="+ productType + 
      ", Value={" + theProduct.toString() + "}], Quantity={" + 
      quantity + "}");
    return productBuffer.toString();
  }
}
