Lists Alice.

Slides:



Advertisements
Similar presentations
Class-level Methods and Inheritance Part 1 Alice.
Advertisements

Review of Chapter 4 Sections 1 and 2 World-level methods involve two or more objects break a large problem into smaller, logical units follow a design.
While: Indefinite Loops Alice. Repetition In some situations, we don’t know exactly how many times a block of instructions should be repeated. All we.
Introducing While loops (and random numbers too) Alice.
Arrays and Array Visualization
Recursion Alice. Repetition In some situations, we don’t know exactly how many times a block of instructions should be repeated. All we know is that repetition.
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.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Creating An Animation Program Alice Web Design Section 8-4.
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.
Variables and Inheritance A More Complex Example Alice.
Functions Alice.
Creating An Animation Program Alice. Recall We began the animation creation process We introduced the concept of storyboard We will continue using the.
CS320n – Elements of Visual Programming Lists Mike Scott (Slides 9-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
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
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.
Lists Alice. Collections In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing.
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.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Parameters and Event-Handler Methods
Lists and Iteration in Alice
Parameters Section 8-8 Web Design.
Classes, Objects, and World-level Methods
Functions Sec 51 Web Design.
Programming: Simple Control Structures
Arrays and Array Visualization
Variables and Inheritance Part 2
Putting Objects in Motion
Programming: Simple Control Structures
Recursion Alice.
While: Indefinite Loops
Functions Sec 8-11 Web Design.
Recursion Alice.
Parameters Alice.
Programming: Simple Control Structures
Repetition: Definite Loops
Parameters and Event-Handler Methods
Lists Alice.
Creating an Animation Program
List Search Alice.
Programming: Simple Control Structures
Parameters and World-level methods
Programming: Simple Control Structures
Programming: Simple Control Structures
Lists Alice.
Repetition: Definite Loops
Parameters and Event-Handler Methods
Variables and Inheritance Part 1
Functions Alice.
Parameters and Event-Handler Methods
Lists Alice.
Programming: Simple Control Structures
Tutorial for Arrays and Lists
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
List Search Alice.
Ch 9 Lists In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing the same.
Parameters Alice.
Functions Alice.
Programming: Simple Control Structures
Class-level Methods and Inheritance
Parameters and Event-Handler Methods
Functions Alice.
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
Functions Alice.
Variables and Inheritance A More Complex Example
Presentation transcript:

Lists Alice

Collections In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing the same marching steps. In such situations, it is convenient to collect all the objects into a group (a collection)

List One way to organize objects into a collection is to use a list. In our daily lives, we use lists to help us organize things. For example, assignments list shopping list In programming, a list is known as a data structure.

Types of Lists In Alice, a list can be a list of numbers or a list of objects, colors, or other type …. In this session, we will use an example of a list of objects.

Example The famous Rockettes® are preparing for their winter holiday show. You have been hired to create an animation for the holiday show that will be used on a web site where people can purchase tickets for the show.

Creating a list: Step 1 Create the initial world and add five rockette objects to the world. Then, create a new world-level variable in the properties panel. (Why should it be world-level rather than class-level?)

Creating a list: Step 2 In the popup dialog box, type in a name select Object type check “make a List” box click new item button 5 times to select each of the 5 rockettes, one at a time

Programming with a list Now that a list has been created, how do we use the list in a program? One of the most useful operations with a list is to repeatedly perform some action with each item in the list. We call this iteration or "iterating through a list."

Iterating through a list Iteration can be done in two ways: in order (one at a time) all together (simultaneously)

Example: Iteration in Order A typical chorus line dance involves each dancer (one after the other) kicking up one leg. Possible storyboard: kickUpRightLeg Parameter: whichRockette Do in order Do together whichRockette right thigh turn back whichRockette right calf turn forward whichRockette right calf turn back For all dancers in order item_from_dancers kickUpRightLeg

Demo Ch09Lec1Rockette-V1 Concepts illustrated in this example A method that defines an action to be performed by objects in a list is a world-level method (it involves more than one object). In this example, kickUpRightLeg The For all in order statement traverses the list, one list item at a time.

Demo Ch09Lec1Rockettes-V2 Concepts The For all together statement executes the action for all list items simultaneously. The kickUpRightLeg method is still the same. All we did was call the method from within a For all together iterative loop.

Assignment Read Chapter 9 Section 1, Lists

Lab Chapter 9 Lecture 1 Lab