/***************************************************************** * Rectangle * * Member Variables: * int length - represents the length of the rectangle * int width - represents the width of the rectangle * * Private Methods: none * * Public Methods: * Rectangle() - constructor * Rectangle (int l, int w) - constructor * void setLength (int l) - set the rectangle's length * void setWidth (int w) - set the rectangle's width * int getLength() - returns the rectangle's length * int getWidth() - returns the rectangle's width * int computePerimeter() - returns the perimeter as an integer * int computeArea() - returns the area as an integer * void print() - prints the dimensions, perimeter, and area ****************************************************************/ public class Rectangle { // data members int length; int width; /******************************************* * Rectangle Constructor * * Takes no parameters -- sets length and * width to 0 *******************************************/ public Rectangle () { length = 0; width = 0; } /******************************************* * Rectangle Constructor * * Takes length and width as parameters *******************************************/ public Rectangle (int l, int w) { length = l; width = w; } /******************************************* * setLength * * Takes length as a parameter and sets the * member variable length *******************************************/ public void setLength (int l) { length = l; } /******************************************* * setWidth * * Takes width as a parameter and sets the * member variable width *******************************************/ public void setWidth (int w) { width = w; } /******************************************* * getLength * * Returns the rectangle's length *******************************************/ public int getLength() { return length; } /******************************************* * getWidth * * Returns the rectangle's width *******************************************/ public int getWidth() { return width; } /******************************************* * computePerimeter * * Returns the rectangle's perimeter, * computed by summing the sides *******************************************/ public int computePerimeter() { return (width*2 + length*2); } /******************************************* * computeArea * * Returns the rectangle's area, computed * by multiplying length by width *******************************************/ public int computeArea() { return (length*width); } /******************************************* * print * * Prints the length, width, perimeter, and * area of the rectangle *******************************************/ public void print() { System.out.print ("The perimeter of the " + length + "x" + width); System.out.print (" rectangle is " + computePerimeter()); System.out.println (" and the area is " + computeArea()); } } // end of Rectangle class