Pages

Tuesday, May 24, 2011

Midpoint solution

/ * The MidpointFindingKarel class should leave a beeper
* on the corner closest to the center of 1st Street
* (or either of the two central corners if 1st Street has an even
* number of corners). Karel can put down additional beepers as it
* looks for the midpoint, but must pick them up again before it
* stops.*/

import stanford.karel.*;

public class MidpointFindingKarel extends SuperKarel {

public void run()
{
int i;
i=0;
while(frontIsClear())
{
move();
i++;
}
i++;
turnAround();
for(int j=0;j

1 comment: