Class Rectangle

java.lang.Object
Rectangle

public class Rectangle extends Object
This class represents a Rectangle.

There are two new fields:
private double height
private double width

Author:
Bob Myers myers@cs.fsu.edu
  • Field Details

  • Constructor Details

    • Rectangle

      public Rectangle(double height, double width)
      Complete constructor.
      Parameters:
      height - the requested height
      width - the requested width
    • Rectangle

      public Rectangle()
      Empty constructor.

      height and width set to DEFAULT_HEIGHT and DEFAULT_WIDTH respectivly

    • Rectangle

      public Rectangle(Rectangle rectangle)
      Copy constructor.
      Parameters:
      rectangle - this object will have height and width set to copy of incoming rectangle
  • Method Details

    • privateSetHeight

      private void privateSetHeight(double h)
      Set this object's height value.
      Parameters:
      h - set this object height value to the parameter, with a minimum size of SHORTEST_HEIGHT
    • privateSetWidth

      private void privateSetWidth(double w)
      Set this object's width value.
      Parameters:
      w - set this object width value to the parameter, with a minimum size of SHORTEST_WIDTH
    • getHeight

      public double getHeight()
      This object height value.
      Returns:
      this object height value
    • getWidth

      public double getWidth()
      This object width value.
      Returns:
      this object width value
    • setHeight

      public void setHeight(double height)
      Set this object height value.
      Parameters:
      height - set this object height value to the parameter
    • setWidth

      public void setWidth(double width)
      Set this object width value.
      Parameters:
      width - set this object width value to the parameter
    • setRectangle

      public void setRectangle(double height, double width)
      Complete set.
      Parameters:
      height - height
      width - width
    • setRectangle

      public void setRectangle()
      Empty set.

      height and width set to DEFAULT_HEIGHT and DEFAULT_WIDTH respectivly

    • setRectangle

      public void setRectangle(Rectangle rectangle)
      Copy set.
      Parameters:
      rectangle - this object will have height and width set to copy of incoming rectangle data
    • area

      public double area()
      The area of this object.
      Returns:
      the area of this object
    • perimeter

      public double perimeter()
      The perimeter of this object.
      Returns:
      the perimeter of this object
    • toString

      public String toString()
      A String representation of this object.
      Overrides:
      toString in class Object
      Returns:
      Rectangle[height = value, width = value]