CS 1713 Introduction to Computer Science: Spring 2007


Problem from class on 4/25/07:


Draw an accurate schematic diagram of the program variables showing the execution of the program. Assume that the Rectangle class has been appropriately defined with a constructor that has the width and length as parameters in this order.

double x = 2;
double y = 5;
Rectangle r1;
Rectangle r2;
Rectangle r3;
Rectangle[] z;
Rectangle[] w;
r1 = new Rectangle(x,y);
r2 = new Rectangle(x,y);
r3 = new Rectangle(10,20);
z = new Rectangle[2];
z[0] = r1;
z[1] = r2;
w = z;
x = x + 1;
y = y + 2;
r2.setWidth(x);
w[1] = r3;
z[1].setWidth(30);

Solution: