hts.StevenWood.com

[ Last Page ]

Karel 17: SantaBot Tip


SantaBot

SantaBot starts with 10 gifts in his backpack. Here are some tips to help you have "special" Things in the backpack.

Steps:

In your special thing

1. In your special thing: Add a new CONSTRUCTOR. You can have more than one constructor in an object. You must use a constructor that will add a Thing directly to a Robot's backpack- we haven't used this one before. Check the Thing documentation or look at the picture below to see which constructor to set up. Remember your constructor is for your special thing NOT a Thing

Click image for detailed information on this method.
Thing Constructor when held by a robot

 

You must add this second constructor to your special Thing.

Add these THREE lines of code IN the constructor:

  1. Follow the pattern of previous constructors and call "super" with the ONE parameter sent to the method.
    Set the attributes of your special thing:
  2. Add the special icon to your special thing (set the icon size between 0.5 and 0.8; and
  3. set the special thing so you can carry it (check the documentation for the method that does this).

 

In your robot (Santa, Snoopy)

1. In the robot: Use the special robot constructor that gives a robot a certain number of items in its backpack. You used this version of the constructor in Exercise #5, where you created the Robots that sent the message to the Space Station. (Note: you can have more than one constructor in a robot.)

Click image for detailed information on this method.
Robot constructor summary

2. In the robot: Override the makeThing() method.

Click image for detailed information on this method.
Summary of the makeThing() method

This method is used by the robot to add things to its backpack when the "held by" constructor is used. It puts the normal Thing into the backpack.

You can OVERRIDE the method so it will add your version of the Thing (e.g. ones made to look like a present) to the backpack.

First point: this method used a special visibility called protected. Don't worry about that, just leave the top line of the method as is, with protected visibility and having it return a Thing (don't change the return type to your special Thing).

top line of makeThing method

Next, do these TWO things IN the makeThing method:

  1. Create one of your special Things using the "held by" constructor.
    e.g. SpecialThing x = new SpecialThing (.... ) // inside the brackets, put the word used to represent the robot
  2. Return the special Thing. (All methods that have a type MUST return the "answer", in this case the answer is your newly created special Thing.) HINT: What is the name of the special Thing? That name represents the item to return.
    e.g. return nameOfSpecialThing ;

 

 

[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+