MidpointFindingKarel

MidpointFindingKarel - */ import stanford.karel.*; public...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * File: MidpointFindingKarel.java * ------------------------------- * When you finish writing it, 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. The world may be of any size, but you are allowed to * assume that it is at least as tall as it is wide.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: */ import stanford.karel.*; public class MidpointFindingKarel extends SuperKarel { public void run(){ /* int i; for(i=1;frontIsClear();i++){ move(); } turnAround(); for(int j=0;j<(i/2);j++) move(); putBeeper(); */ putBeeper(); while(frontIsClear()){ move(); } turnAround(); while(noBeepersPresent()){ if(noBeepersPresent()) putBeeper(); if(frontIsClear()) move(); while(noBeepersPresent()&&frontIsClear()) move(); pickBeeper(); turnAround(); if(frontIsClear()) move(); } } }...
View Full Document

This note was uploaded on 10/25/2010 for the course CS 106A at Stanford.

Ask a homework question - tutors are online