10a-class-examples

10a-class-examples - CS 106A Handout #10A June 24, 2009...

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

View Full Document Right Arrow Icon
Handout #10A CS 106A June 24, 2009 The Eight Versions of the Mountain Climbing Problem Thanks to Eric Roberts for basically this entire handout /* * File: MountainKarel1.java * ------------------------- * The MountainKarel1 subclass gets Karel to climb a simple * mountain, plant a flag, and descend to the ground. This * version works only for the specific world shown in the * handout. */ import stanford.karel.*; public class MountainKarel1 extends Karel { public void run() { turnLeft(); move(); turnLeft(); turnLeft(); turnLeft(); move(); turnLeft(); move(); turnLeft(); turnLeft(); turnLeft(); move(); putBeeper(); move(); turnLeft(); turnLeft(); turnLeft(); move(); turnLeft(); move(); turnLeft(); turnLeft(); turnLeft(); move(); turnLeft(); } }
Background image of page 1

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

View Full DocumentRight Arrow Icon
– 2 – /* * File: MountainKarel2.java * ------------------------- * The MountainKarel2 subclass gets Karel to climb a simple * mountain, plant a flag, and descend to the ground. This * version works only for the specific world shown in the * handout, but does define turnRight to simplify the code. */ import stanford.karel.*; public class MountainKarel2 extends Karel { public void run() { turnLeft(); move(); turnRight(); move(); turnLeft(); move(); turnRight(); move(); putBeeper(); move(); turnRight(); move(); turnLeft(); move(); turnRight(); move(); turnLeft(); } /* Turns Karel 90 degrees to the right. */ private void turnRight() { turnLeft(); turnLeft(); turnLeft(); } }
Background image of page 2
– 3 – /* * File: MountainKarel3.java * ------------------------- * The MountainKarel3 subclass gets Karel to climb a simple * mountain, plant a flag, and descend to the ground. This
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

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

Page1 / 8

10a-class-examples - CS 106A Handout #10A June 24, 2009...

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

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