-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStoneMasonKarel.java
55 lines (43 loc) · 911 Bytes
/
StoneMasonKarel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* 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(){
for(int i=0; i<3; i++){
fixRow();
for(int j=0; j<4; j++){
move();
}
}
fixRow();
}
private void fixRow(){
turnLeft();
while(frontIsClear()){
if(noBeepersPresent()){
putBeeper();
move();
}else{
move();
}
}
if(noBeepersPresent()){
putBeeper();
}
turnAround();
moveToWall();
}
private void moveToWall(){
while(frontIsClear()){
move();
}
turnLeft();
}
}