ReviewSessionPracticeSolutions - REVIEW SESSION PRACTICE...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
REVIEW SESSION PRACTICE MIDTERM SOLUTIONS RockClimbingKarel public class RockClimbingKarel extends SuperKarel { public void run() { moveToWall(); turnLeft(); climbRock(); putBeeper(); } private void moveToWall(){ while (frontIsClear()){ move(); } } private void climbRock(){ climbToTop(); positionAtEdge(); } private void climbToTop(){ while (rightIsBlocked()){ if (frontIsClear()){ move(); } else { moveToNextEdge(); } } } private void moveToNextEdge(){ turnLeft(); move(); turnRight(); move(); } private void positionAtEdge(){ turnRight(); move(); } }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
RandomClickDrag public class RandomClickDrag extends GraphicsProgram{ private static final double MAX_LEN = 200; private static final double MIN_LEN = 100; private double lastX ; private double lastY ; private GObject currentRect ; private RandomGenerator rgen = new RandomGenerator(); public void run(){ addMouseListeners(); } public void mouseClicked(MouseEvent e){ currentRect = getElementAt(e.getX(), e.getY()); if ( currentRect != null ){ ((GRect) currentRect ).setFillColor(
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/18/2010 for the course CS 106A taught by Professor Sahami,m during the Fall '08 term at Stanford.

Page1 / 4

ReviewSessionPracticeSolutions - REVIEW SESSION PRACTICE...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online