Computer Programming (for)

  • Uploaded by: Bank
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Computer Programming (for) as PDF for free.

More details

  • Words: 388
  • Pages: 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(); }

}

Related Documents


More Documents from "Bank"

Aim Star
June 2020 19
June 2020 18
June 2020 17