milewalker
This is an old revision of the document!
MileWalker.java
import kareltherobot.*; public class MileWalker extends Robot // note the capital letters for the class name { public MileWalker(int street, int avenue, Direction direction, int beepers) { super(street, avenue, direction, beepers); } public void moveMile() { move(); move(); move(); move(); // one line to conserve space move(); move(); move(); move(); } // note the robot name is not used }
MileWalkerRunner
import kareltherobot.*; /** * * @author Chris Thiel * @version Aug 19, 2019 * A Class with a main method to run a MileWalkerRobot * similar to 3.3 page 34 * */ public class MileWalkerRunner implements Directions { public static void main(String[] args) { World.setDelay(50); World.setVisible(); task(); } public static void task(){ // Declare a instance of a MileWalker: MileWalker lisa = new MileWalker (3, 2, East, 0); // declare a MileWalker robot lisa.moveMile(); // call the new method lisa.pickBeeper(); // call an old method lisa.turnLeft(); lisa.move(); lisa.pickBeeper(); lisa.moveMile(); lisa.turnOff(); } }
milewalker.1566567376.txt.gz · Last modified: 2019/08/23 09:36 by frchris