import java.lang.Math; /* to take square roots later on */
import java.util.Vector; /* to access the Vector class */
class Figurettes
{
/* *********************************************************** */
/* Main method. Should not include any methods other than main */
/* *********************************************************** */
public static void main(String[] args)
{
Rectangle r = new Rectangle("rectangle");
Square s = new Square("square extends rectangle");
Triangle t = new Triangle("right triangle");
Vector all = new Vector();
r.setParameters(2.0, 4.0); /* setting up the parameters */
s.setParameters(3.0); /* for each of the objects */
t.setParameters(3,4);
all.addElement(r); /* adding object to the */
all.addElement(s); /* vector of all objects */
all.addElement(t);
for (int i = 0; i < 3; i++) /* for loop, notice the i++ */
{
Figure f = (Figure)(all.elementAt(i)); /* new variable */
/* ^---------------------- using type casting */
f.computeArea(); /* uses correct method for */
f.computePerimeter(); /* the object automatically */
f.display();
}
}
}