CompSci 94 - Classwork 20- November 19, 2013
Today's classwork first gives you practice with recursion
through three exercises.
You will experiment with Recursion, another way of doing repetition.
- Problem 1 is the Mystery function on another sheet of paper.
- 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
call racehorseGame.moveRandomHorseForward? Explain.
- What happens if you move the recursive call to between whichHorseWon
"I won" and the Else? Explain.
- 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
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