CompSci 4 Fall 2010 Test 1 Solutions 1. C 2. a) There is a missing after the word "frog" b) Apples.png must be an image file. This code displays the picture apples.png three times side by side horizontally. c) Displays as: Duke will win again with "will" in italics and "again" in bold 3) Lynx could not display images or videos. It could also not play sound files or javascript. 4) D 5) A 6) C 7) "move to" moves the center of an object to the center of another object. If the center locations are in different places, then that could cause one object whose center is in the middle of the object to move that center to the feet of another object whose center is at its feet, causing the object to go into the ground. "move" moves in a certain direction, and is not related to centers of objects. 8) a) camel.friend is the function. It returns an object. b) the horse distance to camel must be >= 1 c) 2, squirrel d) amount, animal e) camel.friend f) object g) properties 9) see picture 10) a) 64 b) 25 c) 43 - To get to 43 num1 must == num3 in the first condition, and in the second condition num1 must be greater than num3, those can't both be true. 87 - This can never be returned since the if statement has a return value for each part of it. Those return statements exit the function, so this code is never reached. 11) hawk turn to face bunny hawk move up bunny's height hawk move forward (hawk distance to bunny -2) hawk say squawk Do together hawk move forward 2 meters bunny.upperBody.head turn left 0.25 revs bunny set vehicle to hawk duration=0 Do together hawk move forward 5 meters hawk move up 5 meters 12) motorboat.crush obj balloon, abc prize motorboat turn to face balloon motorboat move forward (motorboat distance to balloon) balloon set isShowing to false motorboat say prize 13A) obj world.possibleHooper obj animal1 obj animal2 obj animal3 if both (animal1's height < hoop's width and animal1's width < hoop's width return animal1 else do Nothing if both (animal2's height < hoop's width and animal2's width < hoop's width return animal2 else do Nothing return animal3 B) world.possibleHooper(animal1=hawk, animal2=flamingo, animal3=chicken) say "I'll fit through the hoop" world.possibleHooper(animal1=hawk, animal2=flamingo, animal3=chicken) turn to face hoop world.possibleHooper(animal1=hawk, animal2=flamingo, animal3=chicken) move forward (world.possibleHooper(animal1=hawk, animal2=flamingo, animal3=chicken) distance to hoop)+5 14) A) 123 kangarooRobot.furthestDistance obj cone1 obj cone2 if ((kangarooRobot distance to cone1)>(kangarooRobot distance to cone2)) return (kangarooRobot distance to cone1 else do nothing return (kangarooRobot distance to cone2) B) obj kangarooRobot.coneFurthestAwayOf3 obj cone1 obj cone2 obj cone3 if (cone1 distance to kangarooRobot)> (kangarooRobot.furthestDistance(cone2, cone3)) return cone1 else if (cone2 distance to kangarooRobot > cone3 distance to kangarooRobot) return cone2 else do nothing return cone3 C) kangarooRobot turn to face kangarooRobot.conefurthestAwayOf3 (cone1 = blackCone, cone2 = yellowCone, cone3 = redCone) kangarooRobot move forward (kangarooRobot distance to (kangarooRobot.coneFurthestAwayOf3(cone1=blackCone, cone2=yellowCone, cone3=redCone))