Thursday, October 4, 2007

Provide yourself an example (not one from your instructor) of how you use a particular command that
will help jog your memory in the future when you need that command again. You must provide a little
code as well as a written explanation with this one.

Look at the following code:

public Rectangle(double x, double y, double width, double height) //creating the edges of the rectangle
{
myX = x;
myY = y;
myWidth = width;
myHeight=height;
}
// now the methods
public double getPerimeter()
{
double perimeter;
return perimeter = myWidth + myWidth + myHeight + myHeight;
}


Here myWidth has to be used when calculating the perimeter instead of width because width is an unspecified variable. This code, for example, would not work:
...
return perimeter = width + width + height + height;

No comments: