CompSci 4 Test 2 Solutions Fall 2007 1A. When the world starts When up arrow is typed While ToadStool is above book 1B. world.myFirstMethod dewdropWillowwind move wheely turn to face... toadStool Turn left ... toadStool Move Down ... toadStool Move Up... 1C. wheely turns to face toadstool toadStool turns around and slowly moves down until it is below ground, then the toadStool moves up and all this repeats forever. 2. 0 chicken 1 husky 2 hare 3 flamingo 3. You need a local variable to store the random number and the maximum should be 5 to get numbers up to 5 but not including 5. 123 temp = random number integer only=true, minimum=2, maximum=5 penguin resize temp penguin resize 1/temp 4A. says hi 9 times 4B. above 4C. 6 meters 5.while (zombie distance to zeus > 0.3) zeus move forward 0.5 meters zombie turn to face zeus zombie move forward 0.7 meters zombie says "Gotcha" 6. timer.decrementAndRest 123 startValue decrement timer.value by 1 timer set text to timer.value as a string if (timer.value < 1) coach say "Reset Timer" timer.value set value to startValue timer set text to timer.value as a string else Do Nothing 7A. obj world.firstAnimalOfColor color=someColor For all world.animals, one item_from_animals at a time if item_from_animals.color == someColor Return item_from_animals else Do Nothing return trex 7B. world.equalizer obj someAnimal For all world.animals, one item_from_animals at a time if someAnimal is taller than item_from_animals item_from_animals resize (someAnimal's height / item_from_animal's height) else do nothing 7B. (alternative solution) world.equalizer obj someAnimal For all world.animals, one item_from_animals at a time while someAnimal is taller than item_from_animals item_from_animals resize 1.01 8A. (Note: use AV for ArrayVisualization) 123 world.indexOfTallest 123 tallest = 0 Loop 123 index from 1 up to (but not including) AV's size incrementing by 1 if the value at AV[index]'s height > the value at AV [tallest}'s height tallest set value to index else do nothing Return tallest 8A (alt solution) // compute tallest object first obj world.Tallest 123 tallest = the value at ArrayVisualization[0]'s height Loop 123 index from 1 up to (but not including) AV's size incrementing by 1 if the value at ArrayVisualization[index]'s height > tallest world.Tallest set value to the value at ArrayVisualization[index] else do nothing // now find the tallest Loop 123 index from 0 up to (but not including) AV's size incrementing by 1 if the value at ArrayVisualization[index] == world.Tallest return index else do nothing return 0 // should return before you get here. 8B. 123 world.NumberVisible 123 count = 0 Loop 123 index from 0 up to (but not including) 6 incrementing by 1 if the value at ArrayVisualization[index].isShowing count set value to (count +1) else do nothing return count