Advertisement
Guest User

StoneMasonKarel

a guest
Nov 10th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 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.        
  19.         private void columnBuilding () {
  20.                 if (facingEast ()) {
  21.                         if (frontIsBlocked()) {
  22.                                 turnLeft () ;
  23.                         } else {
  24.                         turnLeft () ;
  25.                         }
  26.                         if (noBeepersPresent()) {
  27.                                 putBeeper () ;
  28.                         }      
  29.                         while (beepersPresent()) {
  30.                                 move () ;
  31.                                 if (noBeepersPresent()) {
  32.                                         putBeeper () ;
  33.                                 }
  34.                         if (frontIsBlocked()) {
  35.                                 if (noBeepersPresent()) {
  36.                                         putBeeper () ;
  37.                                 }
  38.                                 restart () ;
  39.                         }      
  40.                         }
  41.                 }
  42.         }
  43.        
  44.         private void restart () {
  45.                 turnAround () ;
  46.                 while (frontIsClear()) {
  47.                         move () ;
  48.                 }
  49.                 if (frontIsBlocked()) {
  50.                         turnLeft () ;
  51.                         for (int i=0; i<4;i++)
  52.                                 move () ;
  53.                 }
  54.                 columnBuilding () ;
  55.         }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement