Skip to content

Instantly share code, notes, and snippets.

@NatashaTheRobot
Created October 28, 2011 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NatashaTheRobot/1321630 to your computer and use it in GitHub Desktop.
Save NatashaTheRobot/1321630 to your computer and use it in GitHub Desktop.
This is the solution to the CollectNewspaperKarel problem in the online Stanford CS 106A class
/*
* File: CollectNewspaperKarel.java
* --------------------------------
* At present, the CollectNewspaperKarel subclass does nothing.
* Your job in the assignment is to add the necessary code to
* instruct Karel to walk to the door of its house, pick up the
* newspaper (represented by a beeper, of course), and then return
* to its initial position in the upper left corner of the house.
*/
import stanford.karel.*;
public class CollectNewspaperKarel extends SuperKarel {
public void run () {
MoveToNewspaper ();
PickUp ();
Return ();
}
private void MoveToNewspaper () {
move ();
move ();
turnRight ();
move ();
turnLeft ();
move ();
}
private void PickUp () {
pickBeeper ();
turnAround ();
}
private void Return () {
for (int i = 0; i < 3; i++) {
move();
}
turnRight ();
move ();
turnRight ();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment