CS105 HW # 2
Due Wednesday of Fourth Week.

Do not use Alice to answer the following questions.  If you need help, talk to the instructor or a TA. As always, if you receive help from anyone, put an acknowledgment in your solution. In the code segments below parameters are represented as a list of items after the method or function name.   The type of the parameter is indicated in square brackets. For example "bunny.throwAnvil ( [Obj] squashThis)" describes the class level method throwAnvil associated with the class bunny.  This method has one parameter, squashThis, which is of type object. 
  1. Computer Science Autobiography (accidentally left off HW#1)

    Write a short (1-2 paragraph) statement addressing the following questions: When you are finished, e-mail me the autobiography. Be sure to include CS105 in the title of your e-mail. (2pts)
  2. Methods and Parameters (Ch. 4)

    The following piece of code was taken from an unfinished Alice world. The author's goal is to create a new class: SquashingBunny. SquashingBunnies have the ability to drop objects on their victims. The author wants to be able to use SquashingBunnies in any world he creates. What's wrong with the code below? (2pts) (Don't worry about the beauty of the animation. The question here is whether or not this code will work at all.) What would be a better way for the author to organize this code if he or she wants to be able to put squashing bunnies in multiple worlds? (2pts)

      bunny.throwAnvil ( [Obj] squashThis)
           Do in order
           bunny.gotoAnvil
      anvil move to squashThis ( right = 0 , up = 2 , forward = 0 )
      Do together
           anvil move down 2 meters
      squashThis resize 0.5 top to bottom


      bunny.gotoAnvil ( )
           bunny turn to face anvil
      bunny move forward ( bunny distance to anvil )

  3. Nested If/Else Statements and Functions (Ch. 6)

    The following segment of code was exported from an unfinished Alice world.  Replace each block of question marks with an explanation of what has to be true for that portion of the program to be executed.  For example: "This happens if the Chicken is wider than the penguin, and the penguin is taller than the chicken." (4pts)

      world.my first method ( )
           If ( ( subject = Chicken 's width ) > ( subject = penguin 's width ) )
           If ( world.mysteryFunction input1 = Chicken input2 = penguin )
           //???????
      Else
        //???????
      Else
        If ( world.mysteryFunction input1 = penguin input2 = Chicken )
           //???????
      Else
        //???????


      Boolean world.mysteryFunction ( [Obj] input1, [Obj] input2)
           If ( ( subject = input1 's height ) > ( subject = input2 's height ) )
           Return true
      Else
        Return false
  4. Definite Loops (Ch. 7)

    Fill in the number of times the code inside  each inner loop is executed in the following code. (2pts)

      world.my first method ( )
           Loop 5 times times
           Do in order
           Loop 2 times times
           // # of times this happens:
      Loop 10 times times
           // # of times this happens:
  5. While Loops (Ch. 7)

    Assuming the penguin's initial distance above the ground is zero, how many times does he move up in the following code segment (1pt)?

      world.my first method ( )
           While ( ( penguin distance above ground ) < 5 )
           penguin move up 1 meter

    How many times does he move up in this code segment (1pt) ?

      world.my first method ( )
           While ( ( penguin distance above ground ) <= 5 )
           penguin move up 1 meter