Code for Example 6 Catalog class

package tut;		
import com.ibm.telephony.beans.media.*;
import com.ibm.telephony.wvr.*;
/**
 * Subcomponent that allows the caller to order an item from a catalog
 */
class Catalog {
	//Define the category for all the voice segments in this class.
	private static final String CATEGORY = "Tutorials";
	// Define the menu items
	private static final String ITEM1_YES = "Yes";
	private static final String ITEM2_NO  = "No";
	
	// Create an array to store the menu items
	private static final String[] MENU_ITEMS = { ITEM1_YES, ITEM2_NO };
	// Define the keys used to make the menu selections, and store them in an array
	private static final String[] MENU_KEYS = { "1", "2" };
	// Create a number of Voice Segment objects
	// Create the segment objects for the menu items, and store them in an array
	private static final MediaType[]  MENU_PROMPTS = {
		new VoiceSegment(CATEGORY, "ForYesPress1"),
		new VoiceSegment(CATEGORY, "ForNoPress2")
	};
	// Create the segment objects for taking the order
	private static final VoiceSegment VS_PRODUCT_NUMBER = new VoiceSegment(CATEGORY, "ProductNumber");
	private static final VoiceSegment VS_QUANTITY       = new VoiceSegment(CATEGORY, "Quantity");
	private static final VoiceSegment VS_YOU_ORDERED    = new VoiceSegment(CATEGORY, "YouOrdered");
	private static final VoiceSegment VS_ITEMS          = new VoiceSegment(CATEGORY, "Items");
	
	// Create the segment object for the verifying the order menu
	private static final VoiceSegment VS_IS_THIS_OK = new VoiceSegment(CATEGORY, "IsThisOK");
	
	// Create the segment object for the result
	private static final VoiceSegment VS_MAIL_ORDER = new VoiceSegment(CATEGORY, "MailOrder");
	
	// Create AudioNumber objects to play the caller's order back to them
	private AudioNumber prodNumValue  = new AudioNumber();
	private AudioNumber quantityValue = new AudioNumber();
	// Create a media sequence of the caller's order
	private MediaType[] order = { VS_YOU_ORDERED, quantityValue, VS_ITEMS, prodNumValue };
	// Create some attribute objects for getting the product number from the caller
	private PlayAttributes prodNumPlayAtts   = new PlayAttributes();
	private InputAttributes prodNumInputAtts = new InputAttributes();
	private DTMFAttributes prodNumDTMFAtts   = new DTMFAttributes();
	private RecoAttributes prodNumRecoAtts   = null;
	// Create some attribute objects for getting the quantity from the caller
	private PlayAttributes quantityPlayAtts   = new PlayAttributes();	
	private InputAttributes quantityInputAtts = new InputAttributes();
	private DTMFAttributes quantityDTMFAtts   = new DTMFAttributes();
	private RecoAttributes quantityRecoAtts   = null;
	
	// Create some attribute objects for the verify order menu
	private PlayAttributes menuPlayAtts  = new PlayAttributes();
	private MenuAttributes menuAtts      = new MenuAttributes(MENU_PROMPTS, MENU_ITEMS, MENU_KEYS, null); 	
	private DTMFAttributes menuDTMFAtts  = new DTMFAttributes();
	private RecoAttributes menuRecoAtts  = null;
	// Create a constructor method to set up various attributes
	public Catalog() {
		// Set the style of the product number AudioNumber object to digits
		prodNumValue.setStyle("Digits");
		// Set the attributes for getting the product number
		prodNumInputAtts.setMessage(VS_PRODUCT_NUMBER);
		prodNumInputAtts.setTimeout(10);
		prodNumDTMFAtts.setMaximumKeys(4);
		prodNumDTMFAtts.setDelimiterKeys("");
		
		// Set the attributes for getting the quantity
		quantityInputAtts.setMessage(VS_QUANTITY);
		quantityInputAtts.setTimeout(10);
		
		// Set the attributes for the verify order menu
		menuAtts.setHeaderMessage(VS_IS_THIS_OK);
		menuAtts.setTimeout(10);
		menuDTMFAtts.setMaximumKeys(1);
		menuDTMFAtts.setDelimiterKeys("");
	}//Catalog()
	public void takeOrder(Call call) throws WVRException {
		// Create variables to store the product number and quantity of the order.
		double prodNum  = 0;
		double quantity = 0;
		while (true) {
			// Get the product number from the caller
			InputResult prodNumResult = call.playAndGetInput(prodNumPlayAtts, prodNumInputAtts,
                                                       prodNumDTMFAtts, prodNumRecoAtts);
			prodNum = Double.parseDouble(prodNumResult.getValue());
			prodNumValue.setValue(prodNum);
			// Get the quantity from the caller
			InputResult quantityResult = call.playAndGetInput(quantityPlayAtts, quantityInputAtts,
                                                        quantityDTMFAtts, quantityRecoAtts);
			quantity = Double.parseDouble(quantityResult.getValue());
			quantityValue.setValue(quantity);
			// Play the order back to the caller
			call.play(order);
			// Verifies with the caller that the choice is correct, if yes, breaks out of loop
			InputResult input = call.playAndGetInput(menuPlayAtts, menuAtts, menuDTMFAtts, menuRecoAtts);
			String answer = input.getValue();
			if (answer.equals(ITEM1_YES)) break;	
		}//while
		// Confirm to the caller that their order has gone through
		call.play(VS_MAIL_ORDER);
	}//takeOrder()
}