Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class KarelProgram extends Karel
- {
- private void placeHolder(){
- //...
- for (int i = 0; i < 4; i++) {
- }
- }
- public void run()
- {
- while(frontIsClear()){
- if (ballsPresent()){
- move();
- } else{
- putBall();
- move();
- }
- //if right is only clear.
- if (rightIsClear() && leftIsBlocked()){
- putBall();
- putBall();
- }
- //if left is only clear.
- if (leftIsClear() && rightIsBlocked()){
- putBall();
- putBall();
- }
- //if both sides are clear
- if (leftIsClear() && rightIsClear()){
- putBall();
- putBall();
- putBall();
- putBall();
- putBall();
- putBall();
- putBall();
- }
- }
- if(frontIsBlocked()){
- putBall();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement