Advertisement
Guest User

Debugging

a guest
Nov 9th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. /*
  2.  * File: StoneMasonKarel.java
  3.  * --------------------------
  4.  * The StoneMasonKarel subclass as it appears here does nothing.
  5.  * When you finish writing it, it should solve the "repair the quad"
  6.  * problem from Assignment 1.  In addition to editing the program,
  7.  * you should be sure to edit this comment so that it no longer
  8.  * indicates that the program does nothing.
  9.  */
  10.  
  11. import stanford.karel.*;
  12.  
  13. public class StoneMasonKarel extends SuperKarel {
  14.         public void run (){
  15.                 columnBuilding () ;
  16.                 }
  17.        
  18.         private void columnBuilding () {
  19.                 placeColumn () ;       
  20.                 if (facingEast()) {
  21.                         repositionForRowToWest () ;
  22.                         columnBuilding () ;
  23.                 }
  24.                 if (facingWest ()) {
  25.                         repositionForRowToEast () ;
  26.                         columnBuilding () ;
  27.                 }
  28.                 if (facingEast () && frontIsClear()) {
  29.                         columnBuilding () ;
  30.                 }
  31.         }  
  32.        
  33.        
  34.         private void placeColumn () {
  35.                 if (noBeepersPresent ()) {
  36.                         putBeeper () ;
  37.                 } else {
  38.                         for (int i=0; i<4;i++) move () ;
  39.                                 if (noBeepersPresent ()) {
  40.                                         putBeeper () ;
  41.                                 }      
  42.                 }
  43.                 while (frontIsClear()) {
  44.                         for (int i=0; i<4;i++) move () ;
  45.                         if (noBeepersPresent ()) {     
  46.                         putBeeper () ;
  47.                         }
  48.                 }
  49.         }      
  50.        
  51.         private void repositionForRowToWest () {
  52.                 turnLeft () ;  
  53.                 if (frontIsBlocked ()) {
  54.                         turnAround () ;
  55.                 }      
  56.                 move () ;
  57.                 turnLeft () ;
  58.         }
  59.                
  60.         private void repositionForRowToEast () {
  61.                 turnRight () ;
  62.                 if (frontIsBlocked ()) {
  63.                         turnAround () ;
  64.                 }      
  65.                 move () ;
  66.                 turnRight () ; 
  67.         }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement