Created
October 28, 2011 04:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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