Posted on Leave a comment

The first assignment – CollectNewsPaperKarel

Posting my solution to the problem number 1 of assignment 1 of CS106a. Hoping for some feedback to this.

[code lang=”java”]
import stanford.karel.*;

public class CollectNewspaperKarel extends SuperKarel {

public void run(){
MoveToNewsPaper();
pickBeeper();
MoveBackToStart();
}

private void MoveToNewsPaper(){
while(frontIsClear()){
move();
}
turnRight();
move();
turnLeft();
move();

}

private void MoveBackToStart(){
turnAround();
move();
turnRight();
move();
turnLeft();
while(frontIsClear()){
move();
}
turnAround();

}
}

[/code]

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.