User Tools

Site Tools


milewalker

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 Robot:
		MileWalker lisa = new MileWalker (3, 2, East, 0);       
 
		lisa.moveMile();   // call the new method
		lisa.pickBeeper(); // call an old (inherited) method
		lisa.turnLeft();
		lisa.move();
		lisa.pickBeeper();
		lisa.moveMile();
		lisa.turnOff();
	}
}
milewalker.txt · Last modified: 2019/08/23 09:37 by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki