hts.StevenWood.com

Karel 7a

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

Karel 7a

Complete the following in class or for homework.

A. Create a new class DropItRobot (DIR) which is a child of the Robot class.

DIRs always start with 3 items in their backpack.

Override the move method of the DIR so that before it moves it drops two items from its backpack. If it doesn't have two items then it doesn't drop any items.

Start your robot at avenue 2 and street 6 facing North. Instruct your robot to move north and pick up all the Things at each of the 4 corners above it.

Your robot should stop at avenue 0, street 0. Use the 'moveToStreet0' and 'moveToAvenue0' methods developed in Exercise 16.

Use the city file Edmonton.txt.

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

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

B. Create a child of the DIR robot named ChildDIR.

A ChildDIR will have an attribute (also known as an instance variable) that keeps track of how many Things it has picked up. Name the attribute itemsPickedUp (What type will it be?) 

Override the pickThing method of the ChildDIR class, to increase the attribute (instance variable) itemsPickedUp by one (using a mutator method) and then pick up the Thing. 

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

Override the move method of the ChildDIR so that before it moves it drops two items from its backpack WHEN ItemsPickedUp IS LESS THAN 2. If it isn't, then it DOES NOT drop any items.

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

 
 
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+