Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: StoneMasonKarel.java
- * --------------------------
- * The StoneMasonKarel subclass as it appears here does nothing.
- * When you finish writing it, it should solve the "repair the quad"
- * problem from Assignment 1. In addition to editing the program,
- * you should be sure to edit this comment so that it no longer
- * indicates that the program does nothing.
- */
- import stanford.karel.*;
- public class StoneMasonKarel extends SuperKarel {
- public void run (){
- columnBuilding () ;
- }
- private void columnBuilding () {
- if (facingEast ()) {
- if (frontIsBlocked()) {
- turnLeft () ;
- } else {
- turnLeft () ;
- }
- if (noBeepersPresent()) {
- putBeeper () ;
- }
- while (beepersPresent()) {
- move () ;
- if (noBeepersPresent()) {
- putBeeper () ;
- }
- if (frontIsBlocked()) {
- if (noBeepersPresent()) {
- putBeeper () ;
- }
- restart () ;
- }
- }
- }
- }
- private void restart () {
- turnAround () ;
- while (frontIsClear()) {
- move () ;
- }
- if (frontIsBlocked()) {
- turnLeft () ;
- for (int i=0; i<4;i++)
- move () ;
- }
- columnBuilding () ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement