CompSci 94, Test 2, April 2019 Problem 1 --------- Part A The chicken moves right 1, colliding with the tortoise. The chicken moves forward 1. The tortoise moves right 1, colliding with the bunny. The bunny moves forward 1, and then turns around once. Part B A) The bunny and chicken repeatedly move apart until they are 4 or more units apart. They each move three times and then they are more than 4 unites apart. B) The user can press the F key and the yeti moves forward 1 unit, colliding with the tortoise, who moves forward 1 unit. This can happen over and over. Problem 2 --------- A) The birds in the array birds all spread their wings at the same time. Then one a time, in the order they are in the array with chicken first, then eagle, then falcon, then flamingo, then ostrich and finally penguin last, they fold their wings. B) The chicken turns around once, then the flamingo turns around once. C) The chicken turns around twice. The eagle turns around once. The falcon turns around four times. The flamingo turns around three times. Problem 3 --------- Part A) A) a variable B) 8 C) All the penguins must be painted red. D) Mystery goes through all of the penguins in the array penguins. For those that are not red, they have a 1/3 chance of being painted red. Part B) A) WholeNumber B) Mystery counts the number of red penguins that are very visible (opacity greater than .95). C) Mystery returns 1 if there is at least one penguin that is red and very visible, otherwise it returns 0. Problem 4 --------- A. nothing happens. Note that the tortoise is NOT in the visual array. B. The fox should say "far away" C. The penguin should move forward one unit. D. The fox should turn around once. Problem 5 --------- A. The tortoise will say "click on me to start" B. The tortoise will say "click on me to start". Then the user will click on the tortoise. The score object will appear with value 0. The first penguin is clicked on and the score displayed changes to 1. The second penguin is clicked on and the score displayed changes to 2. C. The score that is displayed resets to 0. D. Declare the gameState variable as a textString Scene property. Initialize it to "setup" When you click on the tortoise, change the gameState variable to "play" In the addMouseClickOnObjectListener for penguins, add: if gameState == "play" then call updateScorer In the addMouseClickOnObjectListener for tortoise, add: if gameState == "setup" Then still call initializeScorer but also change the gameState to "play" Note: You could use other types for the gamestate, such as a whole number and then use different numbers to represent different state, such as 0 for setup, 1 for play, 2 for game over. Problem 6 --------- A) Nothing happens, they are in the same array. B) The cow says "hello" and the wolf turns right. C) The camel turns right and the wolf says yikes D) addCollisionStartListener new Sthing[] {this.cow} new Sthing[] {this.horse, this.wolf, this.camel} cow setPaint RED If getSthingFromSetB == this.horse then horse setPaint RED else if getSthingFromSetB == this.wolf then wolf setPaint RED else if getSthingFromSetB == this.camel then camel setPaint RED Problem 7 --------- You need to return early as soon as you see an animal larger than newAnimal. Note we need to calculate the last animal in the array at the end. SJointedModel largestSoFar <- newAnimal for each SJointedModel someAnimal in this.animals if someAnimal getHeight > newAnimal getHeight is true then largestSoFar <- someAnimal return largestSoFar <- ADDED THIS LINE else loop return this.animals [this.animals length - 1 ] <- CHANGED THIS LINE Problem 8 --------- Part A procedure resizeEveryone DecimalNumber minValue DecimalNumber maxValue For each Panda somePanda in this.panda somePanda resize nextRandomRealNumberInRange minValue maxValue Part B procedure changeColor Paint color1 Paint color2 for each Panda onePanda in this.panda WholeNumber someInteger <- nextRandomIntegerFromAUpToAndIncludingB 1, 3 if someInteger == 1 onePanda setPaint color1 else if someInteger == 2 onePanda setPaint color2 Part C WholeNumber function numberOfColorAndShorter SjointedModel creature Paint somecolor WholeNumber num <- 0 for each Panda pandaVariable in this.pandas if Both pandaVariable getPaint == somecolor AND pandaVariable getHeight < creature getHeight num <= num + 1 loop return num NOTE: For any of these parts you could use a count loop or while loop but then you would need an index that you initialize to zero, and update by one each time in the loop.