Solution to CompSci 4, Test 1 - Fall 2006 1. D 2. D 3. A 4. A 5. D 6. C 7. a. item1, item2 b. Chicken, hotDogCart c. number d. object e. move f. world.distance item1=Chicken item2=hotDogCart >= 10 8. If you place a Dummy Camera object in a location, then it is easy to change the view to that location later. It is especially helpful to keep track of the original camera view if the camera is moving around to different views. 9. This is a rough picture, W is whiteRabbit, P is penquin, T is Tortoise | | | _____W P_____T___| . \ . / . \ ./ . \ / ... \ / \ / \ / ____ 10. A. 2 B. 0 11. Chicken turn to face lawnmower Chicken mobe forward chicken distance to lawnmower - 0.5 Do Together Chicken move forward 0.5m + (lawnmover's width)/2 Chicken move up .35 meters Chicken orient to lawnmower Chicken set vehicle to lawnmower lawnmower turn to face tennisnet lawnmower move forward (lawnmower distance to tennisNet - 1) Do Together lawnmower move up (tennisNet's height * 2) lawnmower move forward 1 meter Do Together lawnmower move down (tennisNet's height * 2) lawnmower move forward 1 meter 12. world.PlaceInMiddle obj person, obj structure1, obj structure2 person set isShowing to false person turn to face structure2 person move forward (person distance to structure2) person turn to face structure1 person move forward (structure1 distance to structure2)/2 person set isShowing to true 13. A. obj world.ShorterObject obj object1, obj object2 if object1 is shorter than object2 return object1 else return object2 ALT SOLN obj world.ShorterObject obj object1, obj object2 if object1's height < object2's height return object1 else return object2 B. obj world.ShorterOfThree obj item1, obj item2, obj item3 if item1 is shorter than world.ShorterObject object1=item2, object2=item3 Return item1 else if item2 is shorter than item3 Return item2 else Return item3 ALT SOLN obj world.ShorterOfThree obj item1, obj item2, obj item3 if item1's height < item2's height and item1's height < item3's height Return item1 else // know item1 is not the shortest if item2's height < item3's height Return item2 else Return item3 C. T/F world.isOnlyOneThisColor color objectColor, obj obj1, obj obj2, obj obj3 if obj1.color==objectColor and obj2.color!=objectColor and obj3.color!=objectColor return true else if obj1.color!=objectColor and obj2.color==objectColor and obj3.color!=objectColor return true else if obj1.color!=objectColor and obj2.color!=objectColor and obj3.color==objectColor return true else do nothing Return false ALT SOLN T/F world.isOnlyOneThisColor color objectColor, obj obj1, obj obj2, obj obj3 if (obj1.color== obj2.color and obj1.color==objectColor) or (obj2.color==obj3.color and obj2.color==objectColor) or (obj1.color==obj3.color and obj1.color==objectColor) Return false else Return true D. world.changeShortestRedToBlue obj shape1, obj shape2, obj shape3 if world.ShorterOfThree item1=shape1 item2=shape2 item3=shape3 .color == red // shortest cone is red, also case if all three cones are red world.ShorterOfThree item1=shape1 item2=shape2 item3=shape3 set color to blue else if world.IsOnlyOneThisColor objectColor=red, obj1=shape1, obj2=shape2, obj3=shape3 // only one code is red if shape1.color==red shape1 set color to blue else if shape2.color==red shape2 set color to blue else shape3 set color to blue else // know there are exactly two red cones. if shape1.color== red if shape2.color==red world.shorterObject object1=shape1 object2=shape2 set color to blue else world.shorterObject object1=shape1 object2=shape3 set color to blue else world.shorterObject object1=shape2 object2=shape3 set color to blue