Fundamentals of Programming

"Success is the ability to go from one failure to another with no loss of enthusiasm." Winston Churchill

Chapter 6-2 Exercises

Name____________________________ Checked By: ____________________________

  1. ___ / 13 pts Chapter 6-2, Example with Figure 6-2-4- Worker Bee with Flowers [Page 172-174]
    • ____ [1 pt] Initial World - Worker Bee, two flowers (a red flower and a pink flower)
    • ____ [2 pts] Method - bee fly over to the nearest flower.
    • ____ [6 pts] Question/Function (writing) - Write the World.isFirstCloser function with three parameters called b, f1, and f2 that will represent the comparing object (the bee) and two objects to test which one is closer to the comparing object (comparing the bee with the red flower and the pink flower).
    • ____ [2 pts] Question/Function (return) - World.isFirstCloser function returns True if object the bee is closer to the first flower or False if not.
    • ____ [2 pts] Question (invoking/using/calling function) - World.isFirstCloser function is used (or called) from another method .
      • What is the name of your method that you are calling World.isFirstCloser function from?
      • ____________________________ .
  2. ___ / 10 pts Chapter 6-2, Exercise 1 Creating a question for the Zeus world [Page 177]
    • ____ [1 pts] Initial - Re-load a Zeus world from section 6-1 Exercise 1. Save your new file as Ch6-2ZeusQuestion.a2w
    • ____ [3 pts] Question/Function (write)- Write a World.isPhilosopher, question (function) that receives the clicked object as a parameter.
    • ____ [3 pts] Question/Function (return) - World.isPhilosopher function returns True if the object clicked is one of the four Greek philosophers and False otherwise.
    • ____ [3 pts] Question (call/invoke function) - Use or call the World.isPhilosopher question by modifying the World.shootBolt method to determine whether Zeus should shoot a thunderbolt at the clicked object.
  3. ___ /19 pts Chapter 6-2, Exercise 5 Frighten away the Dragon [page 178]
    • ____ [1 pt] Initial - Create an initial scene of a troll and a dragon as shown on page 179.
    • ____ [4 pts] Method - Troll moves toward dragon to frighten away the dragon from his favorite hunting grounds
      • What is the name of your method? ____________________________
    • ____ [2 pts] - Event - hitting space bar will move the troll toward dragon.
    • ____ [4 pts] - Question (writing function) - write a question/function to determine if the troll is within 5 meters of the dragon.
      • What is the name of your question/function? ____________________________
    • ____ [2 pts] - Question (return function) - the question/function should return True if the troll is within 5 meters of the dragon, False otherwise.
    • ____ [4 pts] - Question (call/invoke function) - use/call your question/function from your method to make the troll rant and rave while moving toward the dragon only if they are more than 5 meters apart.
    • ____ [2 pts] - Question (call/invoke function) - When the troll is less than 5 meters away from the dragon, have the dragon fly away.

TOTAL SCORE: ______ /42 points