Index

Rectangle

Index


Overview


The rectangle is a common every-day object. We see rectangles all over the place.


Photo Credits

Discussion


So why are we taking about rectangles?. Two basic reasons:

That's cool right: Simple but useful.

Rectangle Definition


Here is a nice reference: Rectangle.

A rectangle has a width and height.
The area of the rectangle is the width times the height, or:
area = width * height


The perimeter of the rectangle is distance all the way around the rectangle, or:
perimeter = width + height + width + height
or we can say:
perimeter = 2 * (width + height)
(either works)




In the sketch above, we have:
width = 3
height = 2
area = width * height = 3 * 2 = 6
perimeter = 2 * (width + height) = 2 * 5 = 10


Java Rectangle Class


Okay, now we'll code a Java class to model (mimic) a Rectangle.

The class has been coded for you (with many code comments added) so you can learn from browsing it.

Open this Rectangle.zip and follow the instructions in the README file also shown here for convenience:

Instructions:

Note:
If your working directory is "Scratch" then you should have all of the JAVA files and script files mentioned above all in that one working directory.

Java Advanced Rectangle Class


This section is similar to the previous, except here we program a Java Rectangle class to demonstrate a few more Java features like:

Open this Rectangle.zip and follow the instructions in the README file.

































Photo Credits