/*
 * Rectangle.java
 *
 * Created 10/30/06
 * Last modified 10/30/06
 */

package chapter9;

/**
 * This class is a subclass of the GeometricObject superclass
 * defined in Chapter 9 of Liang, Introduction to Java
 * Programming: Fundamentals First, 6th edition. Some comments
 * have been modified.
 */
public class Rectangle extends GeometricObject {
    
    // ---------------------------------------------------------------------
    // Instance variables (data fields)...

    private double width;
    private double height;

    // ---------------------------------------------------------------------
    // Constructor(s)...

    public Rectangle() {
    }
    
    public Rectangle (double width, double height) {
        this.width = width;
        this.height = height;
    }
    
    // ---------------------------------------------------------------------
    // Methods ("getters", "setters", and others...)

    public double getWidth() {
        return width;
    }
    
    public void setWidth (double width) {
        this.width = width;
    }
    
    public double getHeight() {
        return height;
    }
    
    public void setHeight (double height) {
        this.height = height;
    }
    
    public double getArea() {
        return width * height;
    }
    
    public double getPerimeter() {
        return 2 * (width + height);
    }

    /** This main() method serves as a test facility for creating
     *  Rectangle objects and exercising their methods.
     */
    public static void main (String [] args) {

        // Create a Rectangle with width = 2, height = 4
        Rectangle rectangle = new Rectangle(2, 4);
        rectangle.setColor ("red");
        rectangle.setFilled (true);

        // The following methods are "inherited" from GeometricObject...
        
        System.out.println ("A rectangle " + rectangle.toString());
        System.out.println ("The color is " + rectangle.getColor());
        System.out.println ("The rectangle is " + 
                (rectangle.isFilled() ? "filled" : "not filled"));

        // The following methods are defined only in the subclass Rectangle...

        System.out.println ("The width is " + rectangle.getWidth());
        System.out.println ("The height is " + rectangle.getHeight());
        System.out.println ("The area is " + rectangle.getArea());
        System.out.println ("The perimeter is " + rectangle.getPerimeter());
    }
        
}   // End of Rectangle class definition
