CompSci 94 Exam 2 Fall 2021 Rubric Problem 1 A 1) 18 times A 2) 3 times B) 3 times When amount is 0, 3 and 6. Then amount is 9 and the while condition "amount < 8" is false. Problem 2 A) airplane B) boat C) Any answer that has somenum a number from 9 to 15 and paintColor is any color other than green. For example, somenum is 10 and paintColor is blue, will have the blackCat say train. Problem 3 3A) First all the animals in the array turn around once at the same time. Next, the cow says each of the phrases in the words array one at a time in this order: "hello", "goodbye", "sing", "run", "walk". Next the horse says "run" Next the cow moves down underground, then the fox moves underground, and then the poodle moves underground. 3B) bear says "hello" cow says "goodbye" camel says "sing" fox says "run" [Note the loop only executes four times ] 3C) The variable indexThree is not updating, it stays 0 because the if statement is false the first time (since the first word "hello" does not start with "s"), and the update for indexThree is in the true part of the if statement. This results in an infinite loop. To fix: The line: indexThree <- indexThree + 1 should be moved to be right after the if statement and before the end of the while loop. Then it will update each time through the loop. That would make the loop stop when it is updated to 5. ALTERNATE WAY TO FIX: Add a line: indexThree <- indexThree + 1 in the else. Then in the if true part and the else part the indexThree is always updated. 4. A. Biped B. bunny C. whiteRabbit D. This function returns the first object in the creature array whose height is smaller than the tortoise's height. If there is no object in the array with smaller height, the tortoise is returned. 5. A. The tortoise says hello B. The whiteRabbit turns around once C. The whiteRabbit moves up ad down D. Nothing happens, the whiteRabbit is not in the Visual array of objects that can be clicked on. 6. A. The cow says "Moo", the wolf says "Bark", the moose says "The end" B. Nothing happens C. The moose turns around, the camel says "Water", the moose says "The end" 7. A. The panda moves forward 1.0 colliding with the tortoise, and at the same time the yetiBaby moves backward 1.0 and colliedes with the hare. Next the hare moves backwards 1.0 (due to the collision) and at the same time the panda moves right 1.0. (due to its collision) Next the tortoise moves back 1.0 and then to its left 2.0 and collides with the yetiBaby. Next the hare moves back 1.0 due to the new collision. SHORT VERSION: Panda moves forward 1 and yetibaby moves backward 1.0 at same time. Hare moves back 1.0 and panda moves right 1.0 at the same time Tortoise moves back 1.0, then left 2.0. Hare moves back 1.0 B. A) The panda moves left 1.0 and collides with the Hare. Next the hare moves back 1.0 and then the yetiBaby turns around once. B. B) If the user presses the W key the tortoise moves left and collides with the yetiBaby. That makes the hare move back 1.0 followed by the yetiBaby turning around once. If the user then presses any key other than W, the tortoise moves back 1.0. After pressing a second key the tortoise could collide with the hare making it move back 1.0 and then the yetiBaby turning around once. This could continue forever (press any key, tortoise moves back 1.0 collides with hare which then moves back 1.0 followed by the yetiBaby turning around once.). 8. 8A. The timer starts at 20 and counts down by 1 forever. 8B. addMouseClickOnObjectListener, setOfVisuals this.bunny procedure mouseClicked if this.bunny getPaint == WHITE this.bunny setPaint RED else if this.bunny getPaint == RED this.bunny setPaint BLUE ALT SOLUTION: addMouseClickOnObjectListener, setOfVisuals this.bunny procedure mouseClicked if getModelAtMouseLocation getPaint == WHITE getModelAtMouseLocation setPaint RED else if getModelAtMouseLocation getPaint == RED getModelAtMouseLocation setPaint BLUE ALT SOLUTION addMouseClickOnObjectListener, setOfVisuals this.bunny procedure mouseClicked if this.bunny opacity > .95 this.bunny setPaint RED this.bunny setOpacity .90 else this.bunny setPaint BLUE 8C add event addKeyPressListener if event isKey W this.timer updateTimer -5 OR add event addKeyPressListener if event isKey W this.setTimerNumber timerNumber TimerNumber + 5 this.setValue "" + this.timerNumber 8D. while this.timerNumber > 0 and this.bunny getPaint Not == Blue 8E. Add a boolean variable under scene properties called gameOn and set to False In the addTimerListener event, add an if statement around the code that is there so the code is: if gameOn this.timer updateTimer amount 1 In myFirstMethod, before the while loop set gameOn to true and after the while loop set gameOn to false. ALT SOLN in the addTimeListener event change the code to: if this.timer getTimerNumber > 0 this.timer updateTimer amount 1 9. 9A) procedure paintInRange with parameters DecimalNumber minRange, DecimalNumber maxRange, Paint somePaint for each Panda somePanda in this.pandas if both somePanda getHeight >= minRange and somePanda getHeight <= maxRange some Panda setPaint somePaint 9B) Panda function FirstofColor with parameter Paint paintColor for each Panda onePanda in this.pandas if onePanda getPaint == paintColor return onePanda return this.pandas[0] ALT SOLUTION wholeNumber index <- 0 while index < this.pandas length if this.pandas [index] getPaint == paintColor return this.pandas[index] else do nothing index <- index + 1 loop return this.pandas[0] 9C) If this.FirstOfColor paintColor RED getPaint == RED is true then this.FirstOfColor paintColor RED say "I'm the first red" else this.FirstOfColor paintColor RED say "There are no red pandas"