# Don Slater Wanda Dann

## Presentation on theme: "Don Slater Wanda Dann"— Presentation transcript:

Don Slater dslater@andrew.cmu.edu Wanda Dann wpdann@andrew.cmu.edu15-101Parameters

How does the penguin “push” the ball? Back to the algorithm Do in order penguin swagger penguin push the ball penguin push Do in order penguin move forward to bump into the ball ball move forward to bump into the pin

 Actually, the penguin could be pushing any target object, so we named the procedure pushObject A second procedure

Implement penguin pushObject Do in order this (penguin) move forward to bump into the ball ball move forward to bump into the pin

Only reference to penguin available in the instance menu We say the ball is out-of-scope (unavailable to be used in the penguin class) Problem: How to move the target (ball) We are working in the Penguin class

 A parameter is used to send information to a procedure when the procedure is called (invoked)  Most built-in Alice statements use parameters ◦ move: direction, distance ◦ turn: direction, angleInRotations

pushObject Parameter: target Do in order penguin move forward (to bump into target) target move forward Algorithm with a parameter

Click add parameter A parameter has a type (what kind of parameter is it?) and a name (a placeholder name)

 Available types are listed in a drop-down menu ◦ Specifies the kind of information the parameter will represent Select Type numeric boolean string of text Gallery Classes

Inheritance Hierarchy  The inheritance hierarchy shows the parent classes of our objects  We see that Penguin is a Flyer  BowlingPin is a Prop  We could use these any of these classes (parents or children) as types for our parameter

Other types But the bowling ball is from the SSphere class, which has to be the type selected

The parameter type Provide a name for the parameter Parameter name

 A parameter declaration consists of  Ssphere target  We say “target is of type SSphere” Parameter declaration

 Select parameter from the instance menu The parameter is now in scope

Create instruction for the parameter

pushObject procedural method

Scene class: myFirstMethod  Drag the pushObject tile into the editor  Select an argument (actual parameter) that will be sent to the parameter (formal parameter). We see that we can only choose ball, as it is the only instance of the Ssphere class we have in our program.