Alice in Action with Java

Slides:



Advertisements
Similar presentations
Introduction to Macromedia Director 8.5 – Lingo
Advertisements

Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Alice in Action with Java Chapter 6 Events. Alice in Action with Java2 Objectives Create new events in Alice Create handler methods for Alice events Use.
Monkey See, Monkey Do. Important Turn on Java-like syntax option in Alice, if is not on already.
Repetition Structures
Chapter 10 Introduction to Arrays
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Slides prepared by Rose Williams, Binghamton University Chapter 14 Generics and the ArrayList Class.
Alice in Action with Java
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
Slides prepared by Rose Williams, Binghamton University Chapter 14 Generics and the ArrayList Class.
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
Alice in Action with Java
Chapter 9 Introduction to Arrays
Alice in Action with Java
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 20 Lists, Stacks, Queues, and Priority.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Alice in Action with Java Chapter 6 Events. Alice in Action with Java2 Objectives Create new events in Alice Create handler methods for Alice events Use.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
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.
Chapter 14 Generics and the ArrayList Class Slides prepared by Rose Williams, Binghamton University Copyright © 2008 Pearson Addison-Wesley. All rights.
By Melissa Dalis Professor Susan Rodger Duke University June 2011 Multiplication Table.
Chapter 6: The Repetition Structure
Tutorial 51 Programming Structures Sequence - program instructions are processed, one after another, in the order in which they appear in the program Selection.
Chapter 4 Grouping Objects. Flexible Sized Collections  When writing a program, we often need to be able to group objects into collections  It is typical.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Flow Control: boolean expressions, “if” selection statements (Alice In Action, Ch 4) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September.
Mathematical Expressions, Conditional Statements, Control Structures
Dynamic Data Structures and Generics Chapter 10. Outline Vectors Linked Data Structures Introduction to Generics.
Events (Alice In Action, Ch 6) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012.
Stacks And Queues Chapter 18.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
Alice 3.0 A Guided Tour Mike R-D YRDSB. Agenda General Walkthrough of Alice 3.0 Loops, Variables, Threads Methods / Properties Arrays Misc.
Alice in Action with Java Chapter 5 Lists and Arrays.
Variables (Alice In Action, Ch 3) Slides Credit: Joel Adams, Alice in Action CS120 Lecture 04 7 September 2012.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
GROUPING OBJECTS CITS1001. Lecture outline The ArrayList collection Process all items: the for-each loop 2.
Chapter 5 Array-Based Structures © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Alice in Action with Java Chapter 4 Flow Control.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Methods (part 1) Alice In Action, Ch 2 Slides Credit: Joel Adams, Alice in Action CS120 Lecture August 2012.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
Arrays (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Alice in Action with Java Chapter 4 Flow Control.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Chapter 9 Introduction to Arrays Fundamentals of Java.
Functions (Alice In Action, Ch 3) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012.
Alice in Action with Java Chapter 2 Methods. Alice in Action with Java2 Objectives Build world-level methods to help organize a story into scenes and.
Chapter 3: Variables, Functions, Math, and Strings
Chapter 3: Decisions and Loops
Repetition Control Structures
Alice in Action with Java
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Alice in Action with Java
Dynamic Data Structures and Generics
Object Oriented Programming in java
MSIS 655 Advanced Business Applications Programming
Arrays.
Presentation transcript:

Alice in Action with Java Chapter 5 Lists and Arrays

Objectives Use a list to store multiple items Use Alice’s forAllInOrder and forAllTogether statements Use random numbers to vary the behavior of a program Use an array to store multiple items Alice in Action with Java

Lists and Arrays Some variables only store a single value Number, Boolean, String, Object, Sound, Color Variables that can store multiple values list: container that can dynamically grow and shrink array: container whose size remains fixed at run-time Benefits of using variables that store multiple values Reduces amount of code that needs to be written Makes a program more readable Example: a variable playList that holds 12 songs Pass all 12 songs to a method using one parameter Alice in Action with Java

Lists and Arrays (continued) Alice in Action with Java

List Example 1: Flight of the Bumble Bees Scene 2: a dozen bees rise to defend queen’s honor Set up the scene by adding 12 bees and 1 queenBee Manipulating 12 individual bees leads to inefficiencies Adding 12 bees to a list simplifies implementation Form: Object[]bees = bee, bee2,... bee12; Defining bees list variable in playScene2() Open Create New Local Variable dialog box Select Object type and then make a List Click new item and add the first bee to the list Continue adding new items until the list holds 12 bees Alice in Action with Java

List of Bumble Bees Alice in Action with Java

Processing a List of Bumble Bees Processing list entries Drag the forAllInOrder statement to editing area Drop forAllInOrder, select expressionsbees Construct move()using bee2 as a placeholder Drag item_from_bees onto the placeholder and drop Send turnToFace()message to the queenBee Send say()message with command to queenBee Simulated behavior queenBee turns to each bee and orders it to rise Each bee responds by rising upward 5 meters Alice in Action with Java

List Operations forAllInOrder statement forAllTogether statement Used to sequentially perform actions on list items forAllTogether statement Used to simultaneously perform actions on list items Example: cause all bee objects to take off at once Each item in list is accessed by index (position) Messages can be sent to an entire list or to list items Example 1: aList.clear(); (removes all items) Example 2: aList.add(0, 1); (inserts 1 at list head) Alice in Action with Java

doAllInOrder Alice in Action with Java

doAllTogether Alice in Action with Java

List Operations Alice in Action with Java

List Operations A few list functions Using list functions aList.size(): the number of items in aList aList[i]: the value item i in aList aList.getRandomItem(): random value in aList Using list functions Drag a list definition into the editing area Drop list onto placeholder with function’s return type Alice will display a list of messages to choose from Alice in Action with Java

List Example 2: Buying Tickets Scene 3: line of people waiting to buy tickets Animating the scene using the list data structure Create a new world with a ticket box office Line up five people in front of the ticket window Add five people to the personList Use nested looping to advance the line After an outer loop iteration, the line is reduced by one Testing the animation Compare positions of each person after each iteration Alice in Action with Java

List Example 2: Buying Tickets (continued) Alice in Action with Java

The Array Structure Fixed-size container that can store a group of values Data items are accessed by position (as in a list) Values of data items can be changed at run-time The capacity of an array cannot change at run-time Two reasons for using an array instead of a list The array is more memory-efficient than a list An array is more time-efficient for accessing an item Alice in Action with Java

Array Example 1: The Ants Go Marching User story: soldier ant sings a song while marching View the story as a counting problem The ant song is 10 verses long Most of the lines are repeated A for loop can be used to iterate through 10 verses Managing the differences in lines using parallel arrays One String array stores the verse-specific numbers Another String array stores verse-specific ant actions Values at ith index of array are accessed with each loop Enhance the program by adding a marching method Alice in Action with Java

Array Example 1: The Ants Go Marching Alice in Action with Java

Array Operations Array items are accessed by index (like lists) Predefined operations for arrays anArray[i] = val; (the subscript operation) val.set(value, anArray[i]); anArray.length Two versions of the subscript operation Write version: changes value of item i in the array Read version: retrieves the value of item i in the array Traverse an array using a for loop or while loop forAllInOrder and forAllTogether not available Alice in Action with Java

Array Example 2: Random Access Scene: left castle door tells jokes to right castle door Elements used to program random knock-knock jokes Castle interior with camera positioned before doors Parallel arrays for accessing name and punchline Dialog including name and punchline arrays Use of Random.nextDouble()to generate index Random.nextDouble()details Accessed in the functions pane of world’s details area Set integerOnly attribute to true Define a range of random values for indexing the array Alice in Action with Java

Array Example 2: Random Access (continued) Alice in Action with Java

Summary Data structure: structure storing a group of values List: dynamic container that holds a group of values Array: static container that holds a group of values Item: individual variable stored by index in an array or list forAllInOrder statement: loops through list items in sequence Alice in Action with Java

Summary (continued) forAllTogether statement: applies instructions to list items in parallel Random.nextDouble(): generates random numbers Alice usually displays <None> to indicate that an object value is null Alice in Action with Java