Parameters Alice. Overview The need for more flexible methods Passing a parameter to a method Demos Using the Alice interface to write code for a parameter.

Slides:



Advertisements
Similar presentations
More About Recursion Alice. A second form of recursion A second form of recursion is used when the solution to a problem depends on the ability to break.
Advertisements

As you come in… DOWNLOADS FOR TODAY: Alice Project: Wanda Dann and Don Slater, CMU What do you still need (Alice content/understanding)?
Class-level Methods Alice. World / Class Method World method A general method that may refer to multiple objects; not closely associated with any particular.
Parameters and World-level methods Alice. Our Dragon world The dragon must to take off and fly, to carry the princess.
Parameters and Event-Handler Methods Alice. Mouse input Interactive programs often allow the user to use a mouse to click buttons in a windows-based interface.
Parameters Alice.
Parameters Section 8-8 Web Design. Objectives The student will: Understand what a parameter is Understand how to use a parameter in Alice Understand how.
Programming: Simple Control Structures Part 1 – Conditional Execution Alice.
Arrays and Array Visualization
Tips & Techniques 6 Random Numbers and Random Motion Alice.
More About Recursion Alice. A second form of recursion A second form of recursion is used when the solution to a problem depends on the ability to break.
Fall 2007ACS-1805 Ron McFadyen1 Ch 9 Lists In some animations, several objects must perform the same actions Example: A marching band, where the band members.
Classes, Objects, and World-level Methods Alice. Programming in Alice© 2006 Dr. Tim Margush2 Class / Object Class A template describing the characteristics.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Graphics Object. Group Activity! In each group, pull out one piece of blank paper and one pen or pencil Start with the piece of paper on the left side.
Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.
Arrays and Array Visualization Alice. What is an array? An array is a collection of objects or information that is organized in a specific order. The.
Class-level Methods Chapter 6 part 1. Classes and Objects Classes o In Alice, classes are predefined as 3D models Objects o An object is an instance of.
Today’s Agenda 1.Collect Pre-Lab 5 2.Collect Alice project storyboards 3.Events 4.Dummy Objects 5.Assign pair programming teams and meet upstairs for Lab.
Parameters and Event-Handler Methods Alice. Mouse clicks Interactive programs often allow the user to mouse click an object in the display. buttons in.
What we will do today Learn about functions in Alice.
Functions Alice.
Variables and Inheritance Part 1
Programming: Simple Control Structures Part 2 – Repetition Alice.
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
CompSci 4 Chap 5 Sec 2 Oct 18, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.
Programming: Putting Together the Pieces Built-in Questions and Expressions Alice.
Functions Sec 8-11 Web Design. Objectives The Student will: Understand what a function is Know the difference between a method and a function Be able.
Programming: Simple Control Structures
List Search Alice. Common Uses of Lists Iterating through a list of several like items to accomplish the same task with each item. As in the previous.
Questions Alice. Functionality A question receives value(s), performs some computation on the value(s), and returns (sends back) a value.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
World-level Classes Chapter 6 Part 2. Programs Grow Program code grows larger over time This makes it more difficult to read and process the code in our.
Lists Alice. Collections In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing.
Lists Alice. Collections In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing.
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
CompSci 4 Chap 5 Sec 2 Oct 9, 2008 Prof. Susan Rodger.
List Search Alice. Common Uses of Lists Iterating through a list of several like items to accomplish the same task with each item. As in the previous.
CompSci 4 Chap 9 Sec 1 October 28, 2010 Prof. Susan Rodger.
Parameters Alice. A beetle band Our task is to create an animation for a bug band as an advertisement for their next concert.
Parameters MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum redesign project funded.
CompSci 4 Chap 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
CompSci 4 Chap 5 Sec 1 and 2 Oct 14, 2010 Prof. Susan Rodger.
Tips & Techniques 6 Random Numbers and Random Motion Alice.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Alice Final Project Web Design. Alice Final Project You have a choice of two scenarios: 1. A game of some sort. You must devise a score-keeping mechanism.
Parameters Section 8-8 Web Design.
Functions Sec 51 Web Design.
Arrays and Array Visualization
Functions Sec 8-11 Web Design.
Parameters Alice.
Class-level Methods Alice.
Lists Alice.
Lists Alice.
List Search Alice.
Parameters and World-level methods
<<Project Name>>
Programming: Simple Control Structures
Lists Alice.
Functions Alice.
Lists Alice.
More About Recursion Alice.
List Search Alice.
Parameters Alice.
Functions Alice.
Class-level Methods and Inheritance
Functions Alice.
Functions Alice.
Class-level Methods and Inheritance Part 2
Presentation transcript:

Parameters Alice

Overview The need for more flexible methods Passing a parameter to a method Demos Using the Alice interface to write code for a parameter object

A beetle band Our task is to create an animation for a bug band as an advertisement for their next concert. In the animation, each band member will perform a short solo.

Storyboards Each bug band member will perform a solo. Do together Do in order georgeBeetle move up georgeBeetle move down play sound Do together Do in order ringoBeetle move up ringoBeetle move down play sound Do together Do in order paulBeetle move up paulBeetle move down play sound Do together Do in order lennonBeetle move up lennonBeetle move down play sound

Code for georgeBeetle solo This code will only work for georgeBeetle. Since each band member performs a solo, we will need four versions of the code.

A Better Solution Four versions of very similar code seems a bit tedious. The only things that change are the beetle and the music that plays. A better solution is to write a more flexible method.

Parameters Built-in methods provide flexibility by providing parameters such as distance and direction. Parameters allow you to pass in values (we call the values arguments). Example Parameters: distance, direction Arguments: 0.5 meters, 0.5 seconds

Kinds of Parameters Alice provides several kinds of parameters that can be used in your own methods.

The storyboard Solo: Parameters: bandMember, music Do together Do in order bandMember move up bandMember move down play music Back to our problem… We want to write only one method and use parameters to specify which band member is to perform and which music should be played.

Demo Demonstration of creating a method named solo that can be used for any band member. We will need an Object parameter -- which band member is to play a solo a Sound parameter -- which music should be played

World.solo with parameters.

Calling the solo method Note that in each call to the method, arguments must be given for both parameters.

A Number parameter Let's add a Number parameter to specify the height the bandMember jumps up and down.

Demo Demonstrate the use of a Number parameter to specify the height the bandMember is to jump

Assignment Read Chapter 4-2 Parameters Lab 4-2