# CompSci 94 - Classwork 20- November 19, 2013 10 pts

Today's classwork first gives you practice with recursion through three exercises.

# Recursion

You will experiment with Recursion, another way of doing repetition.

1. Problem 1 is the Mystery function on another sheet of paper.

2. Load the animation Chap08HorseRace.a2w from the CompSci 4 web page under the calendar for today. Run the animation to see what it does.

For the following, write down to turn in an explanation of what happens.

Consider the Race method.

• What happens if you move the recursive call to right after the if/else statement? Explain.

• What happens if you move the recursive call to between the Else and the call racehorseGame.moveRandomHorseForward? Explain.

• What happens if you move the recursive call to between whichHorseWon saying "I won" and the Else? Explain.

3. Load the animation BunnyInGarden.a2w from the CompSci 4 web page. Write the recursive method world.BunnysMeet to do the following (make sure your method uses recursion).
• Two bunnys, bunny and bunny2, repeatedly hop towards each other at the same time as long as they are > 3 meters apart.
• If they are close <= 3 meters apart but still at least 2 meters apart, 1 bunny hops once and they stop hopping.
• When the bunnys are no longer hopping they bow to each other at the same time.