The first assignment – CollectNewsPaperKarel

Posting my solution to the problem number 1 of assignment 1 of CS106a. Hoping for some feedback to this.

import stanford.karel.*;

public class CollectNewspaperKarel extends SuperKarel {

		public void run(){
			MoveToNewsPaper();
			pickBeeper();
			MoveBackToStart();
		}


		private void MoveToNewsPaper(){
			while(frontIsClear()){
				move();
			}
			turnRight();
			move();
			turnLeft();
			move();
			
		}

		private void MoveBackToStart(){
			turnAround();
			move();
			turnRight();
			move();
			turnLeft();
			while(frontIsClear()){
				move();
			}
			turnAround();

		}
}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.