« CS106A: Programming Methodology Assignment Problem Set 1 | Main | CS106A: Programming Methodology Assignment 1.3 »
Wednesday
Dec052012

CS106A: Programming Methodology Assignment 1.4


import stanford.karel.*;

public class MidpointFindingKarel extends SuperKarel {

	int height, width;
	
	// You fill in this part

	public void run() {
		count();
		centerBeeper();
	}
	
	public void count() {
		
		height = 0;
		width = 0;
		
		// count width
		width = width + 1;
		while(frontIsClear()){
			move();
			width = width + 1;
		}
		
//		// return home
//		turnAround();
//		for(int i = 1; i < width; i++){
//			move();
//		}
		
	}
	
	public void centerBeeper() {
		
		turnAround();
		
		for(int i = 0; i < (width/2); i++){
			move();
		}
		
		putBeeper();
		
		turnAround();
	}
	
}