hts.StevenWood.com

Karel 18

Home ] Up ] Karel 7 ] Karel 7a ] [ Karel 18 ][ Last Page ]

Karel 18

Complete the following in class or for homework. Do NOT hand in your work unless other instructions were given.

Create a new class TurnCounterRobot which is a child of the RobotSE class. This new robot will have two instance variables, one that counts the number of right turns and one that counts the number of left turns. Override the turnRight method so that it will add 1 to the number of right turns instance variable before it turns. Override the turnLeft method to add 1 to the number of left turns instance variable and then turn. Add accessor methods for the number of right turns instance variable and for the number of left turns instance variable.

Test your robot using the Rome.txt city file.

Your tester code should:

  1. Start one robot at avenue 0 and street 5 facing North. Instruct this robot to walk around the central set of walls and pick up the yellow Things that are against the wall, then return to the starting position. Finally, display how many right turns and how many left turns were made and how many things are in the robot's backpack.
  2. Start a second robot at avenue 7 and street 0 facing North. Instruct this robot to walk around the central set of walls and pick up the flasher Things that are next to the wall, then return to the starting position. Finally, display how many right turns and how many left turns were made and how many things are in the robot's backpack.

 

Home ] Up ] Karel 7 ] Karel 7a ] [ Karel 18 ][Last Page]
All material on this site is copyright © 1997- by Steven Wood or as credited. All right reserved. Use of this site indicates you agreement with the  terms of use.
Send comments or questions to about this page.
Every attempt has been made to credit work under copyright. If there are any claims that copyright has been missed please contact the .
+SDG+