/*
 * @topic T01015 Integer array and Rectangle object array
 * @brief Rectangle class, constructor, setters/getters, and compareTo
*/
package pckg;
/*
 * Description: This class describes a rectangle object.
 *
 * The class implements Comparable interface with the
 * CompareTo method, which is required for such algorithms
 * as Arrays.sort method and the Arrays.binarySearch method.
 */

public class Rectangle implements Comparable
{
    private double length;     // Instance variables
    private double width;

    //*******************************************************************
    public Rectangle(double l, double w)  // Constructor method
    {
        length = l;
        width = w;
    } // end Rectangle constructor

    //*******************************************************************
    public double getLength()             // getter  
    {
        return length;

    } // end getLength

    //*******************************************************************    	             
    public double getWidth()             // getter  
    {
        return width;
    } // end getWidth

    //*******************************************************************
    public void setLength(double l)      // setter  
    {
        length = l;

    } // end setLength

    //*******************************************************************    	             
    public void setWidth(double w)     // setter  
    {
        width = w;

    } // end setWidth

    //*******************************************************************    
    public double calculateArea()         // calculation method
    {
        return length * width;
    } // end calculateArea

    //*******************************************************************
    public void displayRectangle()         // display method
    {
        System.out.println("Rectangle Length = " + length);

        System.out.println("Rectangle Width = " + width);
    } // end displayRectangle

    //********************************************************************

    public int compareTo(Object o)
    {
        Rectangle R = (Rectangle)o;

        if (this.length < R.length)
        {
            return -1;
        }
        else

            if (this.length > R.length)
            {
                return 1;
            }
        return 0;
    }

} // Rectangle Class