/** * This class represents a Rectangle. * *

There are two new fields: *
private double height *
private double width * * @version 3.0, March 2003 * @author Shayne Steele steele@cs.fsu.edu */ public class Rectangle { /** * define constant for shortest height */ public static final double SHORTEST_HEIGHT = 0.0; /** * define constant for shortest width */ public static final double SHORTEST_WIDTH = 0.0; /** * define constant for default height */ public static final double DEFAULT_HEIGHT = 0.0; /** * define constant for default width */ public static final double DEFAULT_WIDTH = 0.0; /** * height */ private double height; /** * width */ private double width; /** * Set this object's height value. * @param height set this object height value to the parameter, * with a minimum size of SHORTEST_HEIGHT */ private void privateSetHeight(double height) { this.height = (height < SHORTEST_HEIGHT) ? SHORTEST_HEIGHT : height; } /** * Set this object's width value. * @param width set this object width value to the parameter, * with a minimum size of SHORTEST_WIDTH */ private void privateSetWidth(double width) { this.width = (width < SHORTEST_WIDTH) ? SHORTEST_WIDTH : width; } /** * Complete constructor. * @param height the height * @param width the width */ public Rectangle(double height, double width) { privateSetHeight(height); privateSetWidth(width); } /** * Empty constructor. *

height and width set to * DEFAULT_HEIGHT and DEFAULT_WIDTH respectivly */ public Rectangle() { this(DEFAULT_HEIGHT, DEFAULT_WIDTH); } /** * Copy constructor. * @param rectangle this object will have height and * width set to parameter's values */ public Rectangle(Rectangle rectangle) { this(rectangle.height, rectangle.width); } /** * This object height value. * @return this object height value */ public double getHeight() { return (height); } /** * This object width value. * @return this object width value */ public double getWidth() { return (width); } /** * Set this object height value. * @param height set this object height value to the parameter */ public void setHeight(double height) { privateSetHeight(height); } /** * Set this object width value. * @param width set this object width value to the parameter */ public void setWidth(double width) { privateSetHeight(height); } /** * Complete set. * @param height height * @param width width */ public void setRectangle(double height, double width) { setHeight(height); setWidth(width); } /** * Empty set. *

height and width set to * DEFAULT_HEIGHT and DEFAULT_WIDTH respectivly */ public void setRectangle() { setRectangle(DEFAULT_HEIGHT, DEFAULT_WIDTH); } /** * Copy set. * @param rectangle this object will have height and * width set to parameter's values */ public void setRectangle(Rectangle rectangle) { setRectangle(rectangle.height, rectangle.width); } /** * The area of this object. * @return the area of this object */ public double area() { return (height * width); } /** * The perimeter of this object. * @return the perimeter of this object */ public double perimeter() { return (2.0 * (height + width)); } /** * A String representation of this object. * @return Rectangle[height = value, width = value] */ public String toString() { return("Rectangle[height = " + height + ", width = " + width + "]"); } }