SUNY Geneseo Department of Computer Science


Pre- and Postconditions

{Date}

CSci 240, Spring 2007
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture

Questions?

Algorithm Design

Sections 2.2 and 2.3 up to 2.3.2

What is abstraction?

Section 2.3.1 develops an algorithm for making a specific robot draw a square. How should that algorithm really be written for generality?

        static void drawSquare( int size, Robot r ) {
            drawLine( size, r );
            r.turnRight();
            ...
        }
        drawSquare( 4, robbie );
        drawSquare( 10, robin );
        ...
        class DrawingRobot extends Robot {
            void drawSquare( int size ) {
                this.drawLine( size );
                this.turnRight();
                ...
            }
        DrawingRobot r = new DrawingRobot();
        r.drawSquare( 4 );

Example

[A Line Crossing the X Axis]

Hand out problem set 1

Next

Theoretical reasoning about algorithms

Read Sections 3.1 - 3.4, 3.6


Next Lecture