Command | Effect |
move(); | Move Robot one unit in current direction. |
turnLeft(); | Robot turns 90 degrees left. |
pickBeeper(); | Robot picks up a beeper. |
putBeeper(); | Robot puts down a beeper. |
turnOff(); | Turns off robot. |
// file: Mover.jkl class Mover { main { UrRobot karel = new UrRobot (1,1,East,0); // move one block karel.move(); karel.turnOff(); } } |
The class name and the file name must be identical (in the above example the class / file name is Mover).
syntax: className robotName = new className (street, avenue, direction, numberOfBeepers); example: UrRobot karel = new UrRobot (1,1,East,0); |
/* File: SuperRobot.jkl Author: Dr. Cook Date: May 23, 2004 Description: Inheritance */ class SuperRobot extends UrRobot { void turnRight() // new method - make a right turn { turnLeft(); turnLeft(); turnLeft(); } main { SuperRobot alex = new SuperRobot (1, 1, North, 0); alex.turnRight(); alex.turnOff(); } } |
Extends means that SuperRobot inherits all methods from UrRobot.
|
updated: 5/24/2004
Dr. Leah Cook