Class Rectangle
- java.lang.Object
-
- Rectangle
-
public class Rectangle extends java.lang.Object
This class represents a Rectangle.There are two new fields:
private double heightprivate double width- Author:
- Bob Myers
-
-
Field Summary
Fields Modifier and Type Field Description static doubleDEFAULT_HEIGHTdefine constant for default heightstatic doubleDEFAULT_WIDTHdefine constant for default widthprivate doubleheightheightstatic doubleSHORTEST_HEIGHTdefine constant for shortest heightstatic doubleSHORTEST_WIDTHdefine constant for shortest widthprivate doublewidthwidth
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doublearea()The area of this object.doublegetHeight()This object height value.doublegetWidth()This object width value.doubleperimeter()The perimeter of this object.private voidprivateSetHeight(double height)Set this object's height value.private voidprivateSetWidth(double width)Set this object's width value.voidsetHeight(double height)Set this object height value.voidsetRectangle()Empty set.voidsetRectangle(double height, double width)Complete set.voidsetRectangle(Rectangle rectangle)Copy set.voidsetWidth(double width)Set this object width value.java.lang.StringtoString()A String representation of this object.
-
-
-
Field Detail
-
SHORTEST_HEIGHT
public static final double SHORTEST_HEIGHT
define constant for shortest height- See Also:
- Constant Field Values
-
SHORTEST_WIDTH
public static final double SHORTEST_WIDTH
define constant for shortest width- See Also:
- Constant Field Values
-
DEFAULT_HEIGHT
public static final double DEFAULT_HEIGHT
define constant for default height- See Also:
- Constant Field Values
-
DEFAULT_WIDTH
public static final double DEFAULT_WIDTH
define constant for default width- See Also:
- Constant Field Values
-
height
private double height
height
-
width
private double width
width
-
-
Method Detail
-
privateSetHeight
private void privateSetHeight(double height)
Set this object's height value.- Parameters:
height- set this object height value to the parameter, with a minimum size ofSHORTEST_HEIGHT
-
privateSetWidth
private void privateSetWidth(double width)
Set this object's width value.- Parameters:
width- set this object width value to the parameter, with a minimum size ofSHORTEST_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- heightwidth- width
-
setRectangle
public void setRectangle()
Empty set.heightandwidthset toDEFAULT_HEIGHTandDEFAULT_WIDTHrespectivly
-
setRectangle
public void setRectangle(Rectangle rectangle)
Copy set.- Parameters:
rectangle- this object will haveheightandwidthset to parameter's values
-
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 java.lang.String toString()
A String representation of this object.- Overrides:
toStringin classjava.lang.Object- Returns:
- Rectangle[height = value, width = value]
-
-