type.lib
Class Rectangle

java.lang.Object
  extended by type.lib.Rectangle
All Implemented Interfaces:
java.io.Serializable

public class Rectangle
extends java.lang.Object
implements java.io.Serializable

A class that encapsulates a rectangle.

Version:
7.0 - Summer 2010
Author:
H. Roumani, roumani@cse.yorku.ca
See Also:
Serialized Form

Constructor Summary
Rectangle()
          Construct a rectangle with zero width and zero height.
Rectangle(int width, int height)
          Construct a rectangle with the passed width and height.
Rectangle(Rectangle rectangle)
          Construct a copy of the passed rectangle.
 
Method Summary
 boolean equals(java.lang.Object other)
          Determine if this rectangle is the same as the passed one.
 int getArea()
          Determine the area of this rectangle.
 int getCircumference()
          Determine the circumference of this rectangle.
 double getDiagonal()
          Determine the length of the diagonal of this rectangle.
 int getHeight()
          Determine the height of this rectangle.
 int getWidth()
          Determine the width of this rectangle.
 int hashCode()
          Compute a hash code for this Rectangle.
 void setHeight(int height)
          Mutate the height this rectangle.
 void setWidth(int width)
          Mutate the width this rectangle.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Rectangle

public Rectangle()
Construct a rectangle with zero width and zero height.


Rectangle

public Rectangle(int width,
                 int height)
Construct a rectangle with the passed width and height.

Parameters:
width - the width of the rectangle to construct.
height - the height of the rectangle to construct.

Rectangle

public Rectangle(Rectangle rectangle)
Construct a copy of the passed rectangle.

Parameters:
rectangle - the Rectangle object to copy.
Throws:
java.lang.RuntimeException - if rectangle = null
Method Detail

getWidth

public int getWidth()
Determine the width of this rectangle.

Returns:
the width of this rectangle

getHeight

public int getHeight()
Determine the height of this rectangle.

Returns:
the height of this rectangle

getDiagonal

public double getDiagonal()
Determine the length of the diagonal of this rectangle.

Returns:
the length of the diagonal of this rectangle

getArea

public int getArea()
Determine the area of this rectangle.

Returns:
the area of this rectangle

getCircumference

public int getCircumference()
Determine the circumference of this rectangle.

Returns:
the circumference of this rectangle

setWidth

public void setWidth(int width)
Mutate the width this rectangle.

Parameters:
width - the new width

setHeight

public void setHeight(int height)
Mutate the height this rectangle.

Parameters:
height - the new height

equals

public boolean equals(java.lang.Object other)
Determine if this rectangle is the same as the passed one. Two rectangles are considered equal if they have the same width and height.

Overrides:
equals in class java.lang.Object
Parameters:
other - a reference to the object to test equality with.
Returns:
true if other is not null and points to a rectangle that is equal to this one. The return is false otherwise.

hashCode

public int hashCode()
Compute a hash code for this Rectangle.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object.


Java by Abstraction: A Client-View Approach