Advertisement
KevinNT03

Karel - Using For Loops to Run Laps and Put Beepers

Nov 5th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package Activity3;
  2. import kareltherobot.*;
  3.  
  4. public class Activity3Main implements Directions{
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         World.readWorld("Lesson2World.kwld");
  9.         World.setVisible();
  10.         World.setDelay(25);
  11.  
  12.         UrRobot trevor = new UrRobot(5,3, North,20);
  13.  
  14.         for(int x = 0; x < 7; x++){
  15.             trevor.turnLeft();
  16.         }
  17.  
  18.         for(int out = 0; out < 10; out++){ //runs 10 times, total of 5 laps
  19.  
  20.             for (int length = 0; length < 4; length++){ //runs code for the long section of structure
  21.                 trevor.move();
  22.             }
  23.             trevor.turnLeft(); //the robot puts beeper and turns to get ready for the next section
  24.             trevor.putBeeper();
  25.  
  26.             for (int width = 0; width < 2; width++){   //runs code for short section of structure
  27.                 trevor.move();
  28.             }
  29.             trevor.turnLeft(); //the robot puts beeper and turns to get ready for the next section
  30.             trevor.putBeeper();
  31.         }
  32.  
  33.         trevor.move(); //robot moves out of the way to reveal beepers
  34.         trevor.turnLeft();
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement