Create your own jumping cow

Objectives:

  1. Create your own enhanced class
  2. Create a method with a parameter
  3. Create your own function

Directions

  1. Create a new world.
  2. Put a cow into your world.
  3. Select the cow.
  4. Under "cow's details" on the lower left, select the "methods" tab.
  5. Click the "create new method" button and call the new method "jump".
  6. In the "jump" method, have the cow move up 1 meter and down 1 meter, each with a duration of .5 seconds.
  7. In the "jump" method, create a parameter called "numberOfJumps". (It doesn't really matter what you call the parameter as long as it is meaningful.)
  8. In the "jump" method drag the "loop" control. When Alice forces you to choose a number, select "expressions" --> "numberOfJumps".
  9. Put the move up and move down into the loop.
  10. Select the world in the top left.
  11. Under "world's details", select the "functions" tab.
  12. Click the "create new function" button and call it "square". Make sure that it returns a number.
  13. Edit the "square" function and create a new parameter called "num".
  14. Where it says "Return 1", drag "num" to where the "1" is to replace it.
  15. Where it now says "Return num", click on "num", select "math" --> "num *" --> "expressions" --> "world.square.num". Now your function returns num * num or, in math terms, num squared.
  16. Edit "world.my first method", and drag the cow's "jump" method into it. When asked for a number, choose 2.
  17. Run your program. The cow should jump twice.
  18. Now, drag the world's "square" function into the place where the 2 is. The line of code should now contain numberOfJumps = world.square(num = 1). (I am not sure why Alice changes the number back to 1, but that is what it seems to do.)
  19. Where it says "num = 1", change the 1 to a 3.
  20. Run your program. How many times does the cow jump?
  21. Save your jumping cow as follows:
    1. Select the cow in the top left window.
    2. Right-click on the cow (control-click if on a Mac) and select "save object..."
    3. Notice that the default name is "JumpingCow.a2c". (WARNING: If you do not save objects with the ".a2c" suffix, they will not be saved properly. Note that even if the "Files of type" bar says "A2C" that is not good enough. You have to make sure that the ".a2c" suffix is typed.)
    4. Save your file onto the H: drive so that you can use it later. That's all there is to it!

Notes

  1. If you ever want to put a jumping cow into another world, you can now do File --> Import and open the JumpingCow.a2c file. It will insert a JumpingCow for you, just like if you were in the gallery adding an object.

jumpingCow