CompSci 94 Fall 2024 Exam 2 Solutions 1.A 1) The camel says "hello" and then says "Yes" 2) The bear says "Maybe" and then says "No" 1.B 1) pig says four 2) cow says one 3) creature is this.bunny somenumber > 6.1 and <= 8.4 somecolor is yellow 2.A. 1) 18 2) 3 2.B. 1) 3 2) I'm this far from you 0.7 2.C. 1) 4 2) the pig says: "I'm this far from you 1.0" 3.A) Each quadruped in the animals array moves backward 2.0, one at a time in this order: bear, cow, horse, poodle B) Each quadruped in the animals array turns right 1.0, all at the same time. C) The horse moves forward 1 unit, four times. D) Each animal in the array animals, one at a time in this order: Bear, Cow, Horse, Poodle, says the "One". Then each of them one at a time say the "Two". Then each of them one at a time say "Three" 4 a) any three decimal numbers between 2.0 and 3.0 b) 2, 3, 4 c) True, False d) larger e) The move command needs a decimal number for how far to move, so it converts the wholeNumber into a decimal number so it can be used as the distance to move. 5) declare procedure visitFriend with parameter SJointedModel friend do together this.turnToFace friend friend.turnToFace this while this getDistanceTo friend > 2.0 this .walk loop this resize nextRandomDecimalNumberInRange 0.25 2.5 if this.getHeight > friend.getHeight is true then this turn RIGHT 0.25 this turn LEFT 0.5 asSeenBy friend else this say "You are taller" 6) declare procedure randomDirection with parameter DecimalNumber distance constant WholeNumber ranNum <-- nextRandomWholeNumberFromAUpToAndIncludingB 1, 3 constant DecimalNumber num2 <-- nextRandomDecimalNumberInRange 2.0 3.0 if ranNum == 1 is true then this move BACKWARD distance else if ranNum == 2 is true then this move FORWARD distance + num2 else this move UP distance * 2.0 this move DOWN distance * 2.0 *** ALTERNATE SOLN ***: declare procedure randomDirection with parameter DecimalNumber distance constant WholeNumber ranNum <-- nextRandomWholeNumberFromAUpToAndIncludingB 0, 2 if ranNum == 0 is true then this move BACKWARD distance else if ranNum == 1 is true then this move FORWARD distance + nextRandomDecimalNumberInRange 2.0 3.0 else this move UP distance * 2.0 this move DOWN distance * 2.0 7) declare procedure colorAnimal with parameters: Biped animal, Paint color1, Paint color2, Paint color3 animal setPaint color1 while animal getPaint =/= color3 is true constant WholeNumber ranNum <-- nextRandomWholeNumberFromAUpToAndIncludingB 1, 3 if ranNum == 1 is true then animal setPaint color1 else if ranNum == 2 animal setPaint color2 else animal setPaint color3 animal say "What color am I?" loop *** ALTERNATE SOLUTION *** declare procedure colorAnimal with parameters: Biped animal, Paint color1, Paint color2, Paint color3 animal setPaint color1 while not animal getPaint == color3 is true constant WholeNumber ranNum <-- nextRandomWholeNumberFromAUpToAndIncludingB 1, 3 if ranNum == 1 is true then animal setPaint color1 animal say "What color am I?" else if ranNum == 2 animal setPaint color2 animal say "What color am I?" else animal setPaint color3 animal say "What color am I?" loop