Advertisement
seby_stephens

Lesson 4 Activity 2

Dec 4th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. package Lesson4;
  2. import kareltherobot.Robot;
  3. import kareltherobot.World;
  4. //This program uses while loops to move the robot until it hits the tower of beeper and then allows it to climb up tower.
  5.  
  6. public class Activity2Main extends Robot {
  7.     /**
  8.      * Constructorfor Activity2Main class
  9.      * @param a
  10.      * @param s
  11.      * @param d
  12.      * @param b
  13.      * @ return - none
  14.      */
  15.     public Activity2Main(int a,int s,Direction d, int b){
  16.         super(a,s,d,b);
  17.     }
  18.     public static void main(String[] args){
  19.         World.readWorld("Lesson4World2.kwld");
  20.         World.setDelay(100);
  21.         World.setVisible();
  22.         Activity2Main gary = new Activity2Main(1,1,East, 0);
  23.         //Moves robot forward every time there is no beeper
  24.         while(!(gary.nextToABeeper())) {
  25.             gary.move();
  26.         }
  27.         //Turns left when the robot hits the first beeper
  28.         gary.turnLeft();
  29.         //Moves robot forward every time it is on beeper so it climbs up tower
  30.         while(gary.nextToABeeper()){
  31.             gary.move();
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement