UFCFY5-30-1Multimedia Studio Scripting for Interactive Media Declaring and Using Arrays.

Slides:



Advertisements
Similar presentations
UFCFSU-30-13D Technologies for the Web Declaring and Using Arrays in Unity 3D.
Advertisements

Monday, 11/11/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Monday, 11/11/02  Questions? HW 04 due today at 5.  Today – Lists and an introduction to searching.
Programming Logic and Design Sixth Edition
Chapter 10 Introduction to Arrays
Topic 9 – Introduction To Arrays. CISC105 – Topic 9 Introduction to Data Structures Thus far, we have seen “simple” data types. These refers to a single.
General Computer Science for Engineers CISC 106 Lecture 19 Dr. John Cavazos Computer and Information Sciences 04/06/2009.
Programming with Collections Collections in Java Using Arrays Week 9.
B.Sc. Multimedia ComputingMultimedia Authoring Introduction to ActionScript 3.0.
1 Lecture Today’s topic Arrays Reading for this Lecture: –Chaper 11.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
C++ for Engineers and Scientists Third Edition
An Object-Oriented Approach to Programming Logic and Design Chapter 7 Arrays.
Chapter 8 Arrays and Strings
Chapter 9 Introduction to Arrays
B.Sc. Multimedia ComputingMultimedia Authoring Using Arrays in Flash.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - JavaScript: Arrays Outline 11.1 Introduction 11.2 Arrays 11.3 Declaring and Allocating Arrays.
INFO Problem Solving and Programming Logic INFO Problem Solving and Programming Logic Arrays Sorting.
Chapter 8 Arrays and Strings
Topic: An Introduction to JavaScript - from Beginning JavaScript by Wilton (WROX)
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
CMSC 202 Arrays. Aug 6, Introduction to Arrays An array is a data structure used to process a collection of data that is all of the same type –An.
ARRAYS 1 Week 2. Data Structures  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently 
ARRAYS 1 TOPIC 8 l Array Basics l Arrays and Methods l Programming with Arrays Arrays.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
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.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 5 Arrays.
Data Structures and Algorithms Introduction to Algorithms M. B. Fayek CUFE 2006.
Introduction to Data Structures and Algorithms CS 110: Data Structures and Algorithms First Semester,
Neal Stublen Computer Memory (Simplified)  Remember, all programming decisions came down to a true or false evaluation  Consider.
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops Barb Ericson Georgia Institute of Technology August 2005.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Data Collections: Lists CSC 161: The Art of Programming Prof. Henry Kautz 11/2/2009.
Week # 2: Arrays.  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently  Types of data.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
Programming Logic and Design Fourth Edition, Comprehensive Chapter 8 Arrays.
Arrays Chapter 13 How to do the following with a one dimensional array: Declare it, use an index.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
Chapter 8: Part 3 Collections and Two-dimensional arrays.
UFCFY5-30-1Multimedia Studio Scripting for Interactive Media Further Structures for Branching and Looping.
Announcements You will receive your scores back for Assignment 2 this week. You will have an opportunity to correct your code and resubmit it for partial.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 6 Arrays.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
UFCFY5-30-1Multimedia Studio Scripting for Interactive Media Using Interface Fields to Receive and Display Data to the User.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 9: Arrays; Revision Session.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Third Edition by Tony Gaddis.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Introduction to programming in java Lecture 21 Arrays – Part 1.
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
13 Arrays CE : Fundamental Programming Techniques June 161.
Data Structures & Algorithms CHAPTER 2 Arrays Ms. Manal Al-Asmari.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
Chapter 11 - JavaScript: Arrays
Sections 10.1 – 10.4 Introduction to Arrays
Starting Out with Programming Logic & Design
Data Structures (CS212D) Week # 2: Arrays.
Manipulating Pictures, Arrays, and Loops
Arrays Week 2.
Introduction to Data Structure
Arrays & Loops.
Introduction to Computer Science
Presentation transcript:

UFCFY5-30-1Multimedia Studio Scripting for Interactive Media Declaring and Using Arrays

UFCFY5-30-1Multimedia Studio Agenda Why Use an Array Array Declaration in Java Searching and Sorting an Array Using a for - next loop with Arrays Parallel Arrays Array Access Errors

UFCFY5-30-1Multimedia Studio Need to Store Five Numbers Use individual variables for each number stored: int numberOne; int numberTwo; int numberThree; int numberFour; int numberFive; messy - have to process as individual items rather than as a collection of grouped items. Solution - use an Array - contiguous data storage

UFCFY5-30-1Multimedia Studio Arrays and Data Storage Elements The value stored at array element number 2 is 14 Arrays store values in ‘elements’ (compartments) i.e. contiguous memory locations

UFCFY5-30-1Multimedia Studio Arrays and Data Storage Elements The array has 5 elements 0..4 The value stored at array element number 4 is 23 Array element numbering starts at Thus the size of the array is 5

UFCFY5-30-1Multimedia Studio Arrays and Data Types An Array of numbers (integers) Gibson Fender Aria Martin Array of strings Les Paul

UFCFY5-30-1Multimedia Studio Declaring Arrays in Java // create a new array [] numberArray = new int[5]; // store the numbers into the array // numberArray[0] = 15; numberArray[1] = 95; numberArray[2] = 14; numberArray[3] = 70; numberArray[4] = 23;

UFCFY5-30-1Multimedia Studio The for – next Loop // loops for a set number of times for (start; condition; increment) { // do something here }

UFCFY5-30-1Multimedia Studio Accessing Array Elements // iterate through the array for (int index = 0; index <= 4; index++) { System.out.println(numberArray[index]); } // outputs each number in the Array

UFCFY5-30-1Multimedia Studio System Output from for loop

UFCFY5-30-1Multimedia Studio Adding Array Elements // example of declaring specific(literal) values for an array int [] numberValues = {2, 5, 23, 37, 11, 19, 49, 6, 15, 41} ; int total = 0; for (int index = 0; index <= 9; index++){ total = total + numberValues[index]; } System.out.println("The total of all the numbers is:" + total);

UFCFY5-30-1Multimedia Studio Summing the Values of an Array 2 // total the numbers stored in the number array using array // length method int index;// loop control variable int sum = 0; for (index = 0; index <= numberArray.length; index++){ sum = sum + numberArray[index] } System.out.printl("The sum of the numbers in the array is " + sum)

UFCFY5-30-1Multimedia Studio Declaring String Arrays in Java // create a new array String [] nameArray = new String[5]; // store the names into the array nameArray[0] = “Bugs Bunny”; nameArray[1] = “Daffy Duck”; nameArray[2] = “Yosemite Sam”; nameArray[3] = “Mickey Mouse”; nameArray[4] = “Porky Pig”;

UFCFY5-30-1Multimedia Studio for..next loop to output contents for (int index = 0; index <= 4; index++){ System.out.println(nameArray[index]); }

UFCFY5-30-1Multimedia Studio System Output Bugs Bunny Daffy Duck Yosemite Sam Mickey Mouse Porky Pig

UFCFY5-30-1Multimedia Studio for..next loop to search for a match for (int index = 0; index <=4; index++){ if(nameArray[index] == "Mickey Mouse"){ System.out.println("Walt Disney Studios :" + nameArray[index]); } // end if else { System.out.println("Warner Bros. Pictures :" + nameArray[index]); }// end else } // end for

UFCFY5-30-1Multimedia Studio System Output from Search Warner Bros. Pictures :Bugs Bunny Warner Bros. Pictures :Daffy Duck Warner Bros. Pictures :Yosemite Sam Walt Disney Studios :Mickey Mouse Warner Bros. Pictures :Porky Pig

UFCFY5-30-1Multimedia Studio Typical Aspects of using Arrays Search an array for a given value Sort an array in a given order Find the size of the array Use the length method in searching algorithms Compare the contents of one array with another array

UFCFY5-30-1Multimedia Studio Beware! The classic runtime error is where a program tries to access an array element beyond the array’s size. for (index = 0; index <=5; index++) The array has only five elements, but the code is attempting to access element number six (5), which does not exist. The computer speak is the code has ‘fallen off the end of the array’

UFCFY5-30-1Multimedia Studio Parallel Arrays name John Ben Freda Sue Mike

UFCFY5-30-1Multimedia Studio Parallel Array Search name John Ben Freda Sue Mike Search on name Extract on name

UFCFY5-30-1Multimedia Studio Parallel Array Search name John Ben Freda Sue Mike Search on name Find occurrences on name of

UFCFY5-30-1Multimedia Studio Arrays of Data (sounds) Array of.mp3 audio files footsteps.mp3 shell.mp3 siren.mp3 alarm.mp3 ambience.mp3

UFCFY5-30-1Multimedia Studio Summary Arrays are a fundamental structured data type in any programming language Arrays store values usually of the same type in a contiguous way which allows the data to be accessed and manipulated as a collection of data Typical array access is to search and sort the contents Associated data may be held in parallel arrays and use cross referencing to extract the required information Algorithms that manipulate arrays must stay within the array bounds or runtime errors will occur causing the program to ‘freeze’ or ‘crash’.

UFCFY5-30-1Multimedia Studio Revise Last Week’s Concepts Three new coding structures and one new variable type

UFCFY5-30-1Multimedia Studio The Lottery Draw How will this week’s new concepts help to code a solution to the Lottery Draw scenario?

UFCFY5-30-1Multimedia Studio Tutorial Example AFI Movies The first of the American Film Institute (AFI) 100 Years series of cinematic milestones. AFI's 100 Years…100 films is a list of the 100 best American films, as determined by the American Film Institute from a poll of more than 1,500 artists and leaders in the film industry who chose from a list of 400 nominated films. The 100-best list was unveiled in 1998.

UFCFY5-30-1Multimedia Studio Parallel Arrays filmList and userRating filmList userRating Citizen Kane Casablanca The Godfather Gone with the Wind Lawrence of Arabia

UFCFY5-30-1Multimedia Studio Parallel Arrays filmList and userRating Citizen Kane Casablanca The Godfather Gone with the Wind Lawrence of Arabia element 0 not used

UFCFY5-30-1Multimedia Studio var filmList:Array = new Array(); filmList[1] = "Citizen Kane"; filmList[2] = "Casablanca"; filmList[3] = "The Godfather"; filmList[4] = "Gone with the Wind"; filmList[5] = "Lawrence of Arabia";. filmList[99]= "Guess Who's Coming to Dinner"; filmList[100]= "Yankee Doodle Dandy"; AFI Movies Array- filmList

UFCFY5-30-1Multimedia Studio var userRating:Array = new Array(); userRating[1] = 7; userRating[2] = 6; userRating[3] = 8; userRating[4] = 3; userRating[5] = 9;. userRating[99] = 2; userRating[100] = 7; AFI Movies Array- userRating

UFCFY5-30-1Multimedia Studio var index:int // loop variable for the for loop index // two functions to initialize the data setFilms();// initializes the film list setRating(); initializes the user-ratings Index Loop Variable and Array Initialization

UFCFY5-30-1Multimedia Studio // output all the films in the filmList array for(index=1; index <= 100; index++){ trace(filmList[index]); } Output all the films in the filmList Array

UFCFY5-30-1Multimedia Studio // output all the films in the array // and show the user rating for(index=1; index <= 100; index++){ trace(filmList[index] + " " + userRating[index]); } Output all the films and show the user rating

UFCFY5-30-1Multimedia Studio // output all the films where userRating > 7 for(index=1; index <= 100; index++){ if(userRating[index] > 7){ trace(filmList[index] + " " + userRating[index]); } Output all the films with a user rating greater than 7

UFCFY5-30-1Multimedia Studio // output all the films where userRating = 5 for(index=1; index <= 100; index++){ if(userRating[index] == 5){ trace(filmList[index] + " " + userRating[index]); } Output all the films with a user-rating of 5

UFCFY5-30-1Multimedia Studio correct if(userRating[index] == 5)comparison incorrect if(userRating[index] = 5)assignment this will output all the movies! Watch Out for a Logical Error!

UFCFY5-30-1Multimedia Studio // use the these lecture slides to carry out the exercises // e.g. output all the films in the filmList array for(index=1; index <= 100; index++){ // put your code here } Tutorial with Working Code for you to Modify