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.

Slides:



Advertisements
Similar presentations
Visual Lists By Chris Brown under Prof. Susan Rodger Duke University July 2012.
Advertisements

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.
Chapter 10 Introduction to Arrays
Arrays and Array Visualization
Week 2: Primitive Data Types 1.  Programming in Java  Everything goes inside a class  The main() method is the starting point for executing instructions.
CS320n –Visual Programming Random Numbers and Random Motion (Slides 6-3) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Alice in Action with Java
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
Chapter 9 Introduction to Arrays
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Line up By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley This week: Whew!!! The last homework was tough! The homework for this week.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
When you start Photo Story the title screen gives you three options. The following slides will illustrate the directions when “Begin a new story” has been.
Lesson 1 What is Camtasia?. Lesson 2 Editing Objectives After completing the lesson, the student will be able to: Edit a basic recording Camtasia file.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
MAT Meyer Week 2 Programming VB: ‘basics’ Review & preview: Events, variables, statements, etc. Images, Control arrays, For/Next Assignment: read.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
VB Games: Preparing for Memory Brainstorm controls & events Parallel structures (again), Visibility, LoadPicture, User-defined procedures, Do While/Loop,busy.
By Melissa Dalis Professor Susan Rodger Duke University June 2011 Multiplication Table.
PHP Constructs Advance Database Management Systems Lab no.3.
Variables and Inheritance Part 1
Programming: Simple Control Structures Part 2 – Repetition Alice.
1 ball, 2 ball, red ball, blue ball By Melissa Dalis Professor Susan Rodger Duke University June 2011.
CS320n –Visual Programming
CS320n – Elements of Visual Programming Lists Mike Scott (Slides 9-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Can I get your number? By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.
Alice in Action with Java Chapter 5 Lists and Arrays.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Tutorial for Arrays and Lists. Description This presentation will cover the basics of using Arrays and Lists in an Alice world It uses a set of chickens.
Questions Alice. Functionality A question receives value(s), performs some computation on the value(s), and returns (sends back) a value.
S11-1 ADM , Section 11, August 2005 Copyright  2005 MSC.Software Corporation SECTION 11 MACROS: OVERVIEW.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
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.
Chapter 8 P 1 Arrays and Grids Single-dimension arrays Definition An array is a sequence of elements all referred to with a common name. Other terms: table,
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
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 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.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
© 2010 Delmar, Cengage Learning Chapter 11 Creating and Using Templates.
Stack. ADS2 Lecture 1010 The Stack ADT (GoTa §5.1) The Stack ADT stores arbitrary objects Insertions and deletions follow the last-in.
Debugging Watch and Text Output Alice. Debugging Techniques Several techniques are helpful in eliminating errors (bugs) in programs: careful design incremental.
CompSci 4 Chap 10 November 4, 2010 Prof. Susan Rodger.
CompSci 4 Chap 10 Nov 22, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
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.
Variables and Inheritance Part 1 Alice. Review: Properties A class defines properties for its own kind of object. When an object is created (instantiated),
Comparing objects and changing color
Arrays and Array Visualization
Chapter 3: Variables, Functions, Math, and Strings
Chapter 3: Variables, Functions, Math, and Strings
SECTION 3 MACROS: OVERVIEW.
Parameters Alice.
Lists Alice.
Lists Alice.
Lists Alice.
Variables and Inheritance Part 1
Lists Alice.
Parameters Alice.
Class-level Methods and Inheritance Part 2
Presentation transcript:

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 individual components (elements) of an array are of the same type (object, number, color, …).

Analogy An analogy of an array is a music CD. A CD contains a collection of songs, listed in the order recorded. A CD player allows you to play any specific song by selecting its number, or play all the songs in sequence.

Arrays in Alice In Alice, an array is a data structure used to organize objects or information of the same type (object, number, color, etc.) Just as you cannot actually "see" the digital bits of the songs recorded on a CD, you cannot actually "see" the digital information in an array. In other words, an array is not visible.

Array Visualization We will use a built-in 3D model that has been specifically designed to help you "see" how an array works. The elements of this special array visualization are visual Alice objects (of type Object)

Initial World As an example, we will create a visualization of an array of bugs. First, we add five bugs to a new world. This is not yet an array – just five bugs!

Initialize array Now add an arrayVisualization object to the world. A dialog box pops up to allow you to add each bug to the array.

Completed array Each bug added to the array is automatically moved to its location in the array. The locations are numbered 0, 1, 2, 3, 4 (see the numbers in the blue squares). The location number is the index.

elements An arrayVisualization object has a built-in class-level variable, named elements, that keeps track of which objects are in the array and where each is located. The order of the objects in the elements variable matches the order of the objects in the array.

Demo: Access To access (get at) an individual element in the array, create an instruction that uses the index to select the element. Example: This instruction will have the bee, located at index 3, turn around.

Demo: Random Access The built-in random number question can be used to access a random element in an array. Example: Be sure to select the integerOnly option. Why did we choose a maximum of 5?

Permutation Changing the order of elements in an ordered group is a math operation known as creating a permutation. To demonstrate how to perform a permutation, let's write a swap method that exchanges the positions of two elements in an array.

Storyboard Two number parameters are needed, indexOne and indexTwo, to specify the indexes of the two objects to be swapped. A temporary location will be needed to hold one object while the other object changes location. swap: Parameters: indexOne, indexTwo (of type number) Do in order relocate element at indexOne to a temporary location relocate element at indexOne to indexTwo relocate element from temporary location to indexOne

Temporary location An objectVisualization object is added to the world to be used as a temporary holding pen.

Demo: swap

Walking through an array In addition to the ability to access an individual element of an array, it is also possible to "walk through" an array, accessing each element of the array in order.

Demo: Index variable To walk through an array, use the complicated form of the Loop instruction. The index variable is a counter for the loop. In an array, we can also use the index variable to access successive elements in the array.

Assignment Read Chapter 10-2, Arrays Read Tips & Techniques 10, Debugging with Watch and Text Output Lab 10-2