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 () {
- placeColumn () ;
- if (facingEast()) {
- repositionForRowToWest () ;
- columnBuilding () ;
- }
- if (facingWest ()) {
- repositionForRowToEast () ;
- columnBuilding () ;
- }
- if (facingEast () && frontIsClear()) {
- columnBuilding () ;
- }
- }
- private void placeColumn () {
- if (noBeepersPresent ()) {
- putBeeper () ;
- } else {
- for (int i=0; i<4;i++) move () ;
- if (noBeepersPresent ()) {
- putBeeper () ;
- }
- }
- while (frontIsClear()) {
- for (int i=0; i<4;i++) move () ;
- if (noBeepersPresent ()) {
- putBeeper () ;
- }
- }
- }
- private void repositionForRowToWest () {
- turnLeft () ;
- if (frontIsBlocked ()) {
- turnAround () ;
- }
- move () ;
- turnLeft () ;
- }
- private void repositionForRowToEast () {
- turnRight () ;
- if (frontIsBlocked ()) {
- turnAround () ;
- }
- move () ;
- turnRight () ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement