
 /**
 * This class constructs and manipulates a Length object which consists of
 * feet and inches
 * 
 * @author Professor Elizabeth Adams 
 * @version 2 February 7, 2005
 */
public class Length
{
    // instance variables 
    int numberOfFeet, numberOfInches, sign;


   /**
   * default constructor for objects of class Length
   * It has no parameters 
   * It sets initializes instance variables feet & inches to 0
   * by making them parameters in its call to the 2 parameter constructor
   */
   public Length()
   {
				// initialize instance variables
				//numberOfFeet = 0;
				//numberOfInches = 0;
				// call the 2 parameter constructor with 0,0
      this(0,0);
   }

     /** This is the two parameter explicit value constructor
     *   it sets the attribute variables to the values passed in through the parameter list
     *   and calls the three value  constructor with the sign a positive value (i.e. true)
     *
     * @param  numberOfFeet is the object's initial number of feet 
	  * @param  numberOfInches is the object's intial number of inches 
     */
     public Length (int numberOfFeet, int numberOfInches)
     {
	   		/*
		      //  this.numberOfFeet = numberOfFeet;
  		      //  this.numberOfInches = numberOfInches;
				*/
        this (numberOfFeet, numberOfInches, true);  // call to 3 value constructor 
		}  
		  
		/** This is the three parameter explicit value constructor  
	   * It needs to set the int attribute for sign 
     * 
     * @param  numberOfFeet is the initial number of feet in the new object
     * @param  numberOfInches is the initial number of inches in the new object  
     * @param  sign indicates whether the length is positive or not (true if  it is)
     */
     public Length (int numberOfFeet, int numberOfInches, boolean sign)
     {
	   
        this.numberOfFeet = numberOfFeet;
        this.numberOfInches = numberOfInches;
        if (sign)
           this.sign = 1;
        else
           this.sign = -1;
     }

    /**
    * This method alters the calling object's length by adding the parameter object's 
    * length to it.  Remember that each Length object has its own attribute values 
    * which it knows about
    * 
    * @param someLength is the Length whose attributes are to effect the change
    */
  public void changeBy (Length someLength)
  {
       int attributeInches, parameterInches;
      
	 attributeInches =  this.toInches();
    parameterInches = someLength.toInches();
    attributeInches = attributeInches + this.sign * parameterInches;
    this.numberOfFeet = attributeInches/12;
  
    //  this.numberOfInches = attributeInches - (this.numberOfFeet*12);   // OR
    this.numberOfInches = attributeInches % 12;
  }

   /**
   * This method returns true if the calling object's length equals the pararameter
   * object's length
   * 
   * @param  aLength is the object being compared to the calling object
   * @return a boolean telling whether the lengths are equal or not
   */
 
   public boolean equals (Length aLength)
   {    
      boolean returnValue;
      int parameterInches, attributeInches;
      parameterInches = aLength.toInches();
      attributeInches = this.toInches();
      if (parameterInches == attributeInches)
         returnValue = true;
      else
         returnValue = false;    
      return returnValue;
   }
  
     /**
     * This method returns the number of inches in the object's length as a String
     * 
     * @return a String representing the object's length
     */
     public String toString ()
     {

        int callingObjectsValue;  
		  String answer;  
		  callingObjectsValue = this.toInches() ;
		  answer =  (Integer.toString(callingObjectsValue));
		  return answer;
    
     }       

    /** 
     * This method returns the equivalent number of inches in the object's Length
     * 
     * @return The length of the object in inches
     */
     
    private int toInches ()
    {   
   	   // need to convert the number of feet and inches to inches  
	     int totalInches;
     
        totalInches =   this.numberOfInches + 12 * this.numberOfFeet;
        return totalInches; 
    }
       
} // end Length
