CS105      Lab 4.1 - Methods and Parameters

Objectives:

  1. Before starting this lab you should have read Chapter 4.1-4.2 in your text.
     
  2. Start Alice and open the FirstEncounter world that you modified in lab 3.
     
  3. As programs get longer it is useful to break them up into smaller pieces.  For example, in the First Encounter scenario can be divided into the three pieces:
    surprise:  the spiderRobot and the alien surprise each other
    investigate:  the spiderRobot moves closer to investigate the alien
    react:  the alien hides and the spiderRobot sends a message

    We write code (a method) for each of these pieces and the program will simply use (call) each of the methods
     

  4. Follow the instructions on pp92-97 to write the method surprise and call this method.  You can, of course, do the same thing for the other two methods if you wish.
     

  5. Assignment:
    Implement the Confused Kanga scenario on p 130 #2.


     

  6. Open the BeetleBand world from the textbook examples.  We are going to have each of the band members play a musical solo.  Follow the instructions on pp100-103 to import a sound file for each instrument.  The sound files are located in the directory that you downloaded for the course.
     

  7. Since each band member performs similar actions, we will write a method called "solo".  This method will take parameters telling it what band member, instrument, and sound file will be used.  Follow the instructions on pp100-109 on how to use parameters.

     

  8. Assignment:
    Extend the Beetle Band scenario so that two members can play a duet, as described on p131 #5

    Be sure that you use parameters to the duet method for which beetles are playing in the duet!


     


  9.  
    Assignment:
    Implement the Dragons playing chicken scenario on p133 #8

    Be sure to use parameters for the two dragons and their height!

     

  10. Send your three worlds to me in GoucherLearn.