DOC PREVIEW
Duke CPS 004 - Chapter 10

This preview shows page 1-2-19-20 out of 20 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CompSci 4Chap 10 Nov 22, 2005Prof. Susan RodgerNote: thanks to Wanda Dann and Steve Cooper for slide ideasAnnouncements• We will continue to work with arrays next week.• Assignment 7– Storyboard due today– World is due Thursday next week.Research Study Continued• Your choice whether or not to participate• You will be emailed your id number from Camelia Pearson Eaves (LSRC D230)• I do not know your number or whether you choose to participate• Benefit – Take a survey (test) that may help in preparing you for the final exam.What we will do today• Lecture on Chap 10– Review of variables– Introduce arrays of objects• Classwork – practice with arraysReview: Properties•Where is the class?•Where is the object?• A class defines properties• When an object is created it receives is own set of propertiesState and Changing State• State of object –each property stores info about the object–Example:• vehicle• isShowing• State changeClass-level Variables• New variables can be added to the properties of an object– class-level• The value of the variable can be changed– The variable is mutable.– Can be used to track state changes.Inheritance• If an object (and its new variable) are saved out and given a new name, a new class is created.– This is inheritance!– The new class inherits all properties and methods of original class.• Did this before by adding new methods to a class and saving it out.Examples in book• Switch– Add property “isOn”– Boolean type property• Steerable Car– Add property “direction” for amount of turn on front wheels, from –10 to 10– Number type propertyWhat is an array?•An array is a collection of objects or information organized in a specific order• The individual components (elements) are of the same type (all object or all number, etc.)• Analogy – Music CD– Collection of songs listed in order– CD player allows you to• Play songs in order• Play songs by specifying its number• Play songs in random orderArrays in Alice• In Alice, array is a data structure to organize objects or information• An array is not visible, it is a way of organizing• But….– Alice has a 3D model to help you “see” the arrayExample – Create a visualization of an array of people• Add 5 people to the world• Add an array visualization• Not an array yet, must add people to the array• Positions in array numbered starting with 0Initialize array - Add Alice to Array in position 0• Alice automatically moves to the 0 position!Add Soldier to the Array• Soldier moves automatically to position 1 (which is the 2cd position)!Add RandomGuy, Skater and Rockette• The array initialization is complete!• Set isVisible for arrayVisualization to false– Array not seenSetting elements in array• Objects in an array are called elements• Use “let” to set a position in an array• Using “let”.Accessing elements in an array• Can specify an element at a particular location in the arrayRepeat for all items in the array –in order• Use “loop” – complicated version• Note: index in loop is used in body• What does this do?• What does this do?Array vs. List• Array– Elements are ordered– Can access a particular element – 3– Use “Loop” - loop over elements – one at a time, OR every second element, etc•List– Elements are not ordered– Use “For all in order”, “For all together” – does something to each element in the list – just don’t know the order this occursClasswork Today• Introduction to


View Full Document

Duke CPS 004 - Chapter 10

Documents in this Course
Lecture

Lecture

18 pages

Chapter 7

Chapter 7

18 pages

Chapter 9

Chapter 9

15 pages

Java 1

Java 1

24 pages

Java 3

Java 3

11 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

28 pages

Chap 2

Chap 2

16 pages

Graphics

Graphics

20 pages

Lecture

Lecture

12 pages

HTML

HTML

16 pages

Java 1

Java 1

6 pages

Chapter 4

Chapter 4

16 pages

The Plan

The Plan

25 pages

Lecture

Lecture

16 pages

Chapter 6

Chapter 6

21 pages

Lecture

Lecture

18 pages

Lecture

Lecture

23 pages

Lecture

Lecture

16 pages

Lecture

Lecture

19 pages

Lecture

Lecture

12 pages

Lecture

Lecture

5 pages

Lecture

Lecture

26 pages

Lecture

Lecture

16 pages

Chapter 7

Chapter 7

23 pages

Lecture

Lecture

21 pages

Lecture

Lecture

4 pages

Lecture

Lecture

4 pages

Lecture

Lecture

8 pages

Lecture

Lecture

4 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

32 pages

Java

Java

4 pages

CompSci 4

CompSci 4

18 pages

Lecture

Lecture

26 pages

CompSci 4

CompSci 4

12 pages

HTML

HTML

17 pages

Lecture

Lecture

16 pages

Chapter 5

Chapter 5

22 pages

Lecture

Lecture

4 pages

Chapter 4

Chapter 4

10 pages

Chapter 2

Chapter 2

15 pages

Chapter 8

Chapter 8

14 pages

Lecture

Lecture

15 pages

Load more
Download Chapter 10
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Chapter 10 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Chapter 10 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?