import java.text.*;  // because DecimalFormat class is in java.text

	/**
	 *A DecimalFormat that understands the notion of a "field".
	 *That is,you can set the field width of a FieldFormat and
	 *of that width.
	 *
	 * Note:This version is for illustrative purposes only.
	 * It does not override all constructors.
	 *
	 * @author Prof.David Bernstein,James Madison University
	 * @version 1.0
	 */
   
	public class FieldFormat extends DecimalFormat  //FieldFormat is a subclass of DecimalFormat
	{
		private int fieldWidth = -1;   

	/**
	 *Default Constructor
	 */
	public FieldFormat()
   {
		super();  //calling the parent class default constructor
	}

 	/**
	 * Change the length of a String to fit exactly into
	 * a field with the current width
	 *
	 * If the String is lengthened it will be right-justified
	 *
	 * @param original The original String
 	 * @return The shortened or lengthened String
	 */
	public String fitStringToField (String original)
	{
		int 		i;
		String 	returnString;
		
   	returnString = "";    // initializes returnString to the EMPTY string 
		
		if (fieldWidth >0)     //The field width HAS been set
			{
				if (original.length() <= fieldWidth)   //LENGTHEN original
				    // = in line above was unnecessary
				{
					for (i=1; i <= fieldWidth-original.length(); i++)
					{
						returnString = returnString + " ";
					}
					returnString = returnString + original;
				}
				else 											//SHORTEN original
				{
					returnString = original.substring(0,fieldWidth);
					 // Is fieldWidth where you stop or is it the last included value????????
				}
			}
		else 							//The field width HASN'T been set
		{
			returnString = original;
		}
		return returnString;
	} // end fitStringToField
	
	/**
	 *Set the field width
	 *
	 *@param width The width of the field
	 */
	public void setFieldWidth(int width)
	{
		fieldWidth = width;
	} // end setFieldWidth
	
} // end class FieldFormat
	