![]() |
| CS Home » My Home Page » Teaching Archive 2005/6 » COMP1007 » Robot Program |
Robot ProgramThe robot program allows you to write programs to guide a robot around a room, similar to the examples given in the lectures and the problem class questions (but note there are some differences). The robot program consists of a small number of classes, which you need to copy and compile (this also gives an example of how to work with a program consisting of more than one class). To do this follow these steps: 1. Create a new directory to put your robot programs in. Change to that directory. 2. Copy each of the classes below into a file in your new directory, using the correct file name: Remember that the file name must be of the form <classname>.java and the upper/lower case letters must match the class name. You can do the copying by creating a new file from BlueJ or JEdit with the correct name and then copying and pasting the code from the web page. Don't forget to save the file once pasted. 3. Compile the program. From an xterm window compile all the files using: javac *.java If you get errors, check that you copied the source code correctly. Delete files with errors and try again if you can't spot the error. If you have configured JEdit to compile classes then click your compile button, otherwise use the xterm window command line. If you are using BlueJ either click the compile button in the editor window for each class, or right-click on each class icon and select compile, or use the Tools>Compile menu option to compile all files. 4. Run the program from the command line using: java MyRobot This will move the robot around so you can see that the program works. If you have configured JEdit to run programs then click the run button, otherwise use the xterm window command line. From BlueJ right-click on the MyRobot icon and select void main(args) to run the program. When the Method Call dialog box appears just click OK. Alternatively, right-click and select new MyRobot(), and click OK on the Create Object dialog box. Then right-click on the red MyRobot icon and select run from the menu. The Robot program will run without problems on your own PC/Mac if you have Java installed. On a PC use a DOS (Command Prompt) window in place on an xterm window. On a Mac use a Terminal window in place of an xterm (or use an xterm if you have the X-Window server installed).
|
Last updated:
August 31, 2006 |
Computer Science Department - University College London - Gower Street - London - WC1E 6BT -
+44 (0)20 7679 7214 - Copyright 1999-2006 UCL