Solution to CompSci 4, Test 2 - Fall 2006 1A. When the world starts When G is typed While Cow distance to horse1 > 3 1B. world.myfirstmethod horse1.Gallop turn to face - (cow turn to face horse1) move - (cow move forward 1 meter) world.greeting 1C. At the same time, the following things happen 1. Chicken.JumpOnTopOf horse1 is executed 2. BDE is true so cow turns to face horse1 and moves forward 1 meter repeatedly until it is <= 3 meters Then world.greeting is executed. 2. camel cat flamingo 3. Need a local variable to save the random value so it can be used twice Need to generate a random number from 2 to 4 integer only Revised code: 123 randomValue = 0 // declare a local variable randomValue set value to random number minimum=2 maximum=4 integer only=true beachBall move up randomValue meters beachBall move down randomValue meters 4A. 50 meters B. 10 meters 5. while pterodactyl distance to scorpion >= 0.5 meters pterodactyl move forward .25 meters scorpion.waveClaw scorpion set vehicle to pterodactyl pterodactyl move up 6 meters 6. score.IncrementScoreNew if objectClickedOn == obj1 score.value set value to (score.value + 2) score set text to (score.value as a string) else if objectClickedOn == obj2 score.value set value to (score.value + 5) score set text to (score.value as a string) else do nothing 7A. 123 world.HowManyOfThisColor color color 123 count = 1 count set value to 0 For all world.frogs, one item_from_frogs at a time if item_from_frogs.color == color count set value to (count + 1) else do nothing Return count 7B. world.moveBehindBar color color For all world.frogs, every item_from_frogs together if item_from_frogs.color == color item_from_frogs turn right 0.5 revolutions item_from_frogs move forward (item_from_frogs distance to balletBar +1) else Do nothing 8A. obj world.firstshorterAnimal obj someAnimal Loop 123 index from 0 up to but not including 6 times incrementing by 1 if value at ArrayVisualization [index]'s height < someAnimal's height Return the value at ArrayVisualization [index] else Do Nothing Return someAnimal 8B. 123 world.indexOf obj someAnimal Loop 123 index from 0 up to but not including 6 times incrementing by 1 If someAnimal == the value at ArrayVisualization[index] return index else Do nothing Return -1