CompSci 4 Test 2 Fall 2011 Problem 1. A) When the world starts While magicBunny distance to duckPrince > 2.4 When magicBunny distance above ground > 0.5 when duckPrince distance to circle < 1.5 B) world.myFirstMethod magicBunny turn to face duckPrince magicBunny.hop world.ending toadStool move down 0.5 meters toadStool move up 0.4 meters C) When the world starts the magicBunny hops twice over to the duckPrince. With each hop the toadStool sinks 0.5 meters. The duckPrince circles the magicBunny and says "Whee", and in doing so gets close to the circle which makes the toadStool move up a little. This all repeats two more times. At that point the toadStool is below ground so the magicBunny says "Sunk" D) 3 times Problem 2: tiger lion frog tortoise chicken hare Problem 3: A) object B) local variable C) parameter D) world.mystery returns the last penguin in the list that is a specified color. E) world.mystery returns the first penguin in the list that is a specified color. Problem 4: A) 4 B) 12 C) 20 Problem 5: A. timer.cheat if timer.value == 10 timer.value set value to timer.value + 10 else do nothing timer set text to (int timer.value as a string) as a string B. When c is typed, do timer.cheat C. modify the condition on the BDE event to: while timer.value > 0 Begin: Nothing During: timer.decrement End: Nothing Problem 6 world.meeting 123 distance while alienOnWheels distance to aliceLiddell is > 1.5 aliceLiddell says "Come closer, please" distance set value to random number minimum=-1 maximum=2.5 integerOnly = true if distance > aliceLiddell distance to alienOnWheels - 0.5 alienOnWheels move forward aliceLiddell distance to alienOnWheels - 1 else alienOnWheels move forward distance aliceLiddell say "hello" Problem 7: 123 world.numberOutOfOrder loop 123 index from 1 up to (bni) size of world.values incrementing by 1 if item index from world.values < item index-1 from world.values return item index from world.values else do nothing return -1 Problem 8: Part A obj world.tallest color chickcolor obj tallest = none tallest set value to ground for all world.all one item_from_all at a time if item_from_all.color==chickcolor and item_from_all is taller than tallest tallest set value to item_from_all else do nothing return tallest Part B obj world.PickFirstInList color somecolor for all world.all one item_from_all at a time if item_from_all.color==somecolor return item_from_all Part C world.pickteams color teamAColor color teamBColor 123 size loop 123 index from 0 up to (bni) size times incrementing by 1 world.tallest(chickcolor==nocolor) set color to teamAColor world.PickFirstInList(somecolor==nocolor) set color to teamBColor Problem 9 Part A world.indexOutOfOrder loop 123 index from 1 up to (bni) AV's size incrementing by 1 if the value at AV[index] is shorter than the value at AV[index-1] return index return -1 Part B world.fixOrder 123 temp temp set value to world.indexOutOfOrder while (temp >= 0) the value at AV[temp] resize 1.1 temp set value to world.indexOutOfOrder