Harvest Around Square 1 Robot
Code
package HarvestAroundSquare;
import cs1Lib.karel.*;
/** Use a single robot to harvest beepers that are positioned
around a square.
@author Byron Weber Becker
@version 1.0 */
public class HarvestAroundSquare extends KarelApplet
{
public void run()
{ // Read the specification of the world from a URL. Then add the
// world to the applet.
World world = new World(this.getDocumentBase(), "HarvestAroundSquare.txt");
this.add(world);
// Construct a robot with no beepers. Add it to the world.
Robot karel = new Robot();
world.addRobot(karel, 2, 3, World.EAST);
// Instruct the robot to move around the square, picking up
// beepers as it goes.
karel.move();
int side = 0;
while(side < 4)
{ while (karel.frontIsClear())
{ karel.move();
karel.pickBeeper();
}
karel.turnLeft();
side = side + 1;
}
karel.turnOff();
}
}