package r2;

public class Rectangle {
	
	private Double length; // length of rectangle (also width if square)
	private Double width;  // width of rectangle (null if square)
	
	
    /** Constructor: a rectangle with length l and width w.
      * Throw an exception l or w if negative. */
	public Rectangle(double l, double w) {
		length= l;
		width= w;
	}

    /** Constructor: a l x l square.
      * Throw an exception if l negative. */
	public Rectangle(double l) {
		length= l;
	}
	
	/** Return the length of the rectangle */
	public double getLength() {
		return length;
	}
	
	/** Return the width of the rectangle */
	public double getWidth() { 
		return width;
	}
	
	/** Set the length of the rectangle to length */
	public void setLength(double length) { 
		length= length;
	}
	
	/** Set the width of the rectangle to width */
	public void setWidth(double width) { 
		width= width;
	}
	
	/** Return the area of the rectangle */
	public Double getArea() { 
		return length*width;
	}

	/** Return the perimeter of the rectangle */
	public Double getPerimeter(){
		if (width != null) {
			return length + width;
		} else {
			return 2 * length;
		}
	}
	
}
