Anda di halaman 1dari 19

1)

Code
import stanford.karel.Karel;

/**

*/

/**
* @author student

*/

public class GrandFatherKarel extends Karel {

/**

* @param args

*/

public void run() {

while (frontIsClear()) {

for (int i = 0; i < 5; i++) {

fillPothole();

public void fillPothole() {

move();

turnRight();

move();

putBeeper();
turnAround();

move();

turnRight();

move();

public void turnRight() {

turnLeft();

turnLeft();

turnLeft();

private void turnAround() {

turnLeft();

turnLeft();

}
2)

Code
import stanford.karel.Karel;

/**

*/

/**

* @author student

*/

public class FirstKarel extends Karel {

/**

* @param args

*/

public void run() {

while (frontIsClear()) {

move();

while (leftIsClear()) {

turnLeft();

move();
putBeeper();

turnAround();

move();

turnLeft();

move();

turnAround();

while (frontIsClear()) {

move();

while (leftIsClear()) {

turnLeft();

move();

putBeeper();

turnAround();

move();

turnLeft();

move();

}
}

turnAround();

public void turnAround() {

turnLeft();

turnLeft();

}
3)

Code
import stanford.karel.Karel;

/**

*/

/**

* @author student

*/

public class MethodKarel extends Karel {

/**

* @param args

*/

public void run() {

while (frontIsClear()) {

move();

turnRight();
move();

putBeeper();

turnAround();

move();

move();

turnRight();

move();

move();

move();

turnRight();

move();

putBeeper();

turnAround();

move();

turnRight();

move();

move();

move();

turnRight();

move();

putBeeper();
turnAround();

move();

turnRight();

move();

turnLeft();

while (frontIsClear()) {

move();

turnLeft();

while (frontIsClear()) {

move();

turnLeft();

while (frontIsClear()) {

move();

turnLeft();

public void turnRight() {

turnLeft();
turnLeft();

turnLeft();

public void turnAround() {

turnLeft();

turnLeft();

4)
Code

import stanford.karel.Karel;

/**

*/

/**

* @author student

*/

public class SecondKarel extends Karel {


/**

* @param args

*/

public void run() {

turnLeft();

move();

turnRight();

move();

turnLeft();

move();

turnRight();

move();

pickBeeper();

move();

pickBeeper();

move();

turnRight();

move();

turnLeft();

move();

turnRight();

move();

putBeeper();

turnAround();

move();

turnRight();

move();
turnLeft();

move();

turnRight();

move();

move();

turnRight();

move();

putBeeper();

turnAround();

move();

turnRight();

move();

public void turnRight() {

turnLeft();

turnLeft();

turnLeft();

public void turnAround(){

turnLeft();

turnLeft();

}
5)
Code

import stanford.karel.Karel;

/**

*/

/**

* @author student

*/

public class MotherKarel extends Karel {


/**

* @param args

*/

public void run() {

while (frontIsClear()) {

move();

turnLeft();

move();

turnRight();

while (frontIsClear()) {

move();

pickBeeper();

turnLeft();

move();

turnRight();

while (frontIsClear()) {

move();

pickBeeper();

turnLeft();

move();

turnRight();

while (frontIsClear()) {

move();

}
}

public void turnRight() {

turnLeft();

turnLeft();

turnLeft();

Anda mungkin juga menyukai