StoneMasonKarel

 Java |  copy code |? 
01
    import stanford.karel.*;
02
 
03
    public class StoneMasonKarel extends SuperKarel {
04
    public void run() {
05
    //putting beepers into the broken columns in the world
06
 
07
    while (frontIsClear()) {
08
    topOfColumn();
09
    putBeeperInColumn();
10
    nextColumn();
11
    }
12
    topOfColumn();
13
    putBeeperInColumn();
14
    }
15
 
16
    public void topOfColumn() {
17
    //getting to the top of the Column
18
 
19
    turnLeft();
20
    goToWall();
21
    turnAround();
22
 
23
    }
24
    public void putBeeperInColumn() {
25
    //putting beepers into the empty parts of the column
26
 
27
    while (frontIsClear()) {
28
    if (noBeepersPresent()) {
29
    putBeeper();
30
    }
31
    move();
32
    }
33
    if (noBeepersPresent()) {
34
    putBeeper();
35
    }
36
    }
37
    public void goToWall() {
38
    while(frontIsClear()){
39
    move();
40
    }
41
    }
42
    public void nextColumn() {
43
    //going to the next column in the world
44
 
45
    turnLeft();
46
    move();
47
    move();
48
    move();
49
    move();
50
    }
51
 
52
    }

 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Facebook
  • TwitThis
  • StumbleUpon
  • LinkedIn
  • Digg
  • del.icio.us
  • Squidoo
  • Reddit

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>