6.170 Laboratory in Software Engineering
Spring 2000
Amendments to Problem Set 4
Due: March 2, 2000
Handout 10


 

Amendment 1

There is a bug in the specification of the step method in AnimatedThing.  The way velocity is currently updated does not correctly capture the behavior of an animated object being bounced off the borders of the area specified by the argument bound as we would normally expect in the physical world.  Here is the correct specification:

   public void step(Dimension bound)
     // modifies: this
     // effects: Let p = location
     //              v = (vx, vy) = velocity
     //              r = the bounding rectangle of this
     //          Set p_post = p + v
     //          unless (1) part of r is outside bound
     //             => If adding v to p would move r horizontally farther away
     //                from the center of bound,
     //                   set vx_post = -vx
     //                If adding v to p would move r vertically farther away
     //                from the center of bound,
     //                   set vy_post = -vy
     //                Set p_post = p + v_post
     //          or (2) r is within bound but adding v to p would bring
     //                 part of r outside bound
     //             => If r would move outside the horizontal range specified by bound,
     //                   set vx_post = -vx
     //                And if r would move outside the vertical range specified by bound,
     //                   set vy_post = -vy
     //                Set p_post = p
 
 

Amendment 2

Drawing onto a graphics context modifies the graphics context.  Therefore, the specification of the draw method in FigureThing should contain a "modifies" clause.  The correct specification should be as follows:

    public abstract void draw(Graphics g);
     // modifies: g
     // effects: draws this onto g
 
 

Hints