©2007 Felleisen, Proulx, et. al.

4  Methods for Complex Class Hierarchies; Libraries

Portfolio Problems

Pair Programming Assignment

Morphing a Polygon

4.1  Problem

Design the following methods for the classes that represent polygon data that you have defined in the previous two assignments:

  1. Count the number of points in the polygon. (Method name count)

  2. Produce a morphed polygon from two original ones, with the given morphing factor (a number between 0.0and 1.0). Make sure you follow the one task, one method rule. (Method name morphPoly)

  3. Produce a polygon moved by the given distance dx and dy from the given polygon.

  4. Draw the polygon on the Canvas c. (Method name drawPoly) Use a sample program that uses the draw library as a guide - or consult the Help Desk.

4.2  Problem

Design the class that represents a World that contains two polygons (the start and the finish polygon) and keeps track of the elapsed time.

  1. Define the method currentPoly that produces the current polygon based on the elapsed time. This is a follow up on an earlier homework problem.

  2. Define the method draw that draws the current image of the world — i.e the current polygon.

  3. Define the onTick method for this world.

  4. Define the onKeyEvent method that responds to the "up", "down", "left", and "right" key events by moving the polygons 3 pixels in the indicated direction. Note: You must move both the start and the finish polygons.

  5. You can now run your world, using the World’s bigBang method. It you do so, comment out the code before submitting.

Last modified: Friday, October 5th, 2007 2:58:37pm