====== My Solution on Assignment 1 - Problem 2 ====== This is my Solution of Assignment 1 - Problem 2 from the [[http://see.stanford.edu/see/courseinfo.aspx?coll=824a47e1-135f-4508-a5aa-866adcae1111|Computer Science Course CS106A of Prof. Mehran Sahami]] at the [[http://www.stanford.edu|STANFORD University]]. /* * File: StoneMasonKarel.java * -------------------------- * The StoneMasonKarel subclass as it appears here does nothing. * When you finish writing it, it should solve the "repair the quad" * problem from Assignment 1. In addition to editing the program, * you should be sure to edit this comment so that it no longer * indicates that the program does nothing. */ import stanford.karel.*; public class StoneMasonKarel extends SuperKarel { public void run() { // 1st column is allways at starting point while( frontIsClear() ) { repairColumn(); walkNext(); } repairColumn(); } private void repairColumn() { /* Climbs a Columne and fixes it. Falls back down when done. * facing EAST again. */ turnLeft(); while( frontIsClear() ) { if( noBeepersPresent() ) { putBeeper(); } move(); } // Front is now blocked (top on column), drop another beeper if needed. if( noBeepersPresent() ) { putBeeper(); } turnAround(); moveToWall(); turnLeft(); } private void moveToWall() { // Moves Karel all the way straight forward until aproaching a wall while( frontIsClear() ) { move(); } } private void walkNext() { /* walks 4 steps forward */ for( int x=0; x < 4 ; x++ ) { move(); } } } --- //[[mail@awerner.homeip.net|Axel Werner]] 2011-02-05 17:40// {{tag>java karel stanford university cs106 computer science learning programming}}