Advertisement
Guest User

Untitled

a guest
Sep 18th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. public class KarelProgram extends Karel
  2. {
  3. private void placeHolder(){
  4. //...
  5. for (int i = 0; i < 4; i++) {
  6.  
  7. }
  8. }
  9.  
  10. public void run()
  11. {
  12. while(frontIsClear()){
  13. if (ballsPresent()){
  14. move();
  15. } else{
  16. putBall();
  17. move();
  18. }
  19.  
  20. //if right is only clear.
  21. if (rightIsClear() && leftIsBlocked()){
  22. putBall();
  23. putBall();
  24. }
  25.  
  26. //if left is only clear.
  27. if (leftIsClear() && rightIsBlocked()){
  28. putBall();
  29. putBall();
  30. }
  31.  
  32. //if both sides are clear
  33. if (leftIsClear() && rightIsClear()){
  34. putBall();
  35. putBall();
  36. putBall();
  37. putBall();
  38. putBall();
  39. putBall();
  40. putBall();
  41. }
  42. }
  43.  
  44. if(frontIsBlocked()){
  45. putBall();
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement