hts.StevenWood.com

Karel 7

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

Karel 7

Complete the following in class or for homework.

1. Create a new class RememberingRobot (RR) which is a child of the Robot class. This new robot will have an attribute (also known as an instance variable) that keeps track of how many Things it has picked up. Name the attribute pickedThings 

Override the pickThing method of the RR class, to increase the attribute (instance variable) by one and then pick up the Thing. 

Override the move method of the RR class, to change the robot's color (with a RGB green component of 50 * the number of Things picked up), then move. 

You may wish to check the Java API Documentation for the constructors of the Color class. Look at this version of the constructor for detailed information:
Color(int r, int g, int b)

Add mutator methods (sets or adjusts the value of a variable) and accessor methods (get the value of a variable) for the pickedThings instance variable. 

Start your robot at avenue 0 and street 6 facing North. Instruct your robot to move north and pick up a Thing at each of the 4 corners above it. Your robot should stop at avenue 0, street 0. Use the city file Victoria.txt.

Test your program thoroughly. Document task code and new robot class properly.

Do NOT hand in your work unless other instructions were given.

Challenge:

1) Have RR change colour according to the number of things it has picked up (see chart below). When it gets more than 7, the colour doesn't change anymore.

2) Use the chart below, BUT when it has picked up 8 things, it goes back to the same colour as 0 things, when it has picked up 9 things, it goes back to the same colour as 1 thing, etc. The pattern repeats at 16, 24, etc.

3) Use the chart below, BUT when it has reached 8 things, the colour moves back down the list to the same as 6 things, 9 things the same as 5 things, etc.

Things R G B  
0 0 0 0 Black
1 0 64 0  
2 0 128 0  
3 0 255 0 Green
4 128 255 0  
5 128 255 128  
6 196 255 196  
7 255 255 255 White

 

 
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+