We're now ready to write the entire class definition. This
goes into Rectangle.java. This is how it looks:
public class Rectangle
{ // beginning of class definition
// Instance variables
private int width = 0, height = 0 ;
// Default Constructor
public Rectangle()
{
}
// Constructor
public Rectangle( int initWidth, int initHeight )
{
width = initWidth ;
height = initHeight ;
}
// --------------
// Public Methods
// --------------
public void setWidth( int newWidth )
{
width = newWidth ;
}
public void setHeight( int newHeight )
{
height = newHeight ;
}
public int getWidth()
{
return width ;
}
public int getHeight()
{
return height ;
}
public int getPerimeter()
{
return 2 * ( height + width ) ;
}
public int getArea()
{
return width * height ;
}
public boolean isSquare()
{
return width == height ;
}
} // end of class definition