CompSci 4 - Classwork 9- Sep 27, 2011
10 pts

Today's classwork goes along with Chapter 6, Section 1. You will be using built-in functions and writing your own functions to help you have a vehicle that can jump over objects of different size.

Note in each step whether you are writing a function or a method. Also note whether or not it says class or world for the function or method. If it is a function, make sure you select the correct type of return value. If you select the wrong return value, you can't change it, so you will have to start your function over again.

The following work needs to be checked off when you have completed it.

  1. Create a new Alice world with some type of vehicle that has four wheels. Write a class function for this vehicle called numberOfRevolutions (similar to what I did in lecture) that has a distance parameter and returns the number of revolutions a wheel of the vehicle should turn for the given distance. In world.myFirstMethod, add code so your vehicle moves forward and backward with all four wheels having realistic wheel motion.

    OPTIONAL: You might want to write a realistic roll method as I did in lecture to move your vehicle (turning wheels) a certain distance.

  2. Add in two objects, a large object (such as a pyramid or building) and a smaller object (such as a person).

  3. Write a class function for your vehicle called stoppingDistanceInFrontOf that has an object parameter. This function should return two plus twice the width of the object parameter

  4. Write a class function for your vehicle called timeToJump that has an object parameter. This function should return one plus (the object parameter's height divided by 5).

  5. Write a class function for your vehicle called OptimalHeight that has an object parameter. This function should return the object parameter's height plus half of the object parameter's width.

  6. Write a class method for your vehicle called headToObject that has two parameters, a direction and an object. This method should have your vehicle turn to face the object parameter (as seen by the ground), and then realistically roll in the given direction for the distance of the vehicle to the object minus the stoppingDistanceInFrontOf the object.

  7. Write a class method for your vehicle called jumpOver that has one object parameter. This method should at the same time move your vehicle up the OptimalHeight of the object and move the vehicle forward the stoppingDistanceInFrontOf the vehicle. Then the method should at the same time move the vehicle down the OptimalHeight of the object and move the vehicle forward the stoppingDistanceInFrontOf the object. All of these commands should be done in the same amount of time, specifically for the timeToJumpOver the object. (Thus, the total time for this method to execute is twice timeToJumpOver).

  8. Now it is time to use all these methods and functions that you have written.

    Append to world.myFirstMethod code to have your vehicle head to one of the objects and jump over it, then to head to the other object and jump over it. Make sure it starts pretty far away from the objects.

If you finish early, feel free to embelish your animations.