DOC PREVIEW
Duke CPS 004 - Chap 4 Sec 1

This preview shows page 1-2-3-4-5-6 out of 18 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 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 18 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 18 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 18 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 18 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 18 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CompSci 4Chap 4 Sec 1Sept 15, 2005Prof. Susan RodgerAnnouncements• Read Chapter 4, Section 2 for next time• Assignment 3 storyboard due Tuesday– World is due next ThursdayReview• Fish circling around islandjagged smoothShow worldWhat we will do today• Lecture on Chap 4, Sec 1• Classwork– Create two animations• Snowpeople mods including flipping hats• Helicopter– Get checked off today and for last timeLarger Programs• Programs start to increase in size – many lines of code• Games and “real world” applications have thousands, even millions of lines of code• Want to organize large programs into small manageable piecesClasses, Objects and Methods• Object-oriented programming uses classes, objects and methods as basic components• These components help you– Organize large program into small pieces– Design and think about an intricate program– Find and remove errors (bugs)In your programs, you’ve used• Classes– In Alice, classes are predefined as 3D models• Objects– An object is an instance of a class• Class: Chicken• Objects: Chicken, Chicken2In your programs, you’ve also used• Built-in (predefined) methods– Examples: move, turn to face, say• World.my first method– Example: robot on the moon from chapter 2, wrote code where an alien surprised the robot – All the code in World.my first methodModifying the Program• Modify program to get robot to try twice to move toward the alien or the alien go up and down twice.• To make modification, add more lines of code– makes the program code longer and more difficult to read and think about• Show demoA Solution• A solution to the problem is to – Define our own method– Name the new method surprise• Then, can drag-and-drop the surprise method into the edit box, just like the built-in methodsDemo: The Solution• First associate new method with the world• Select World tile• Select methods tab• Click on “create new method”•DemoWorld-level method• surprise is a world-level method because it– Is defined as a method for World– Has instructions that involve more than one object (robot,alienOnWheels)Using the surprise method• This method is executed by calling (invoking) the method from my first method• For testing, invoke temporarily when world startsinvestigate methodreact methodWhy write our own Methods?• Saves time – can call method again and again without rewriting code• Reduces code size – call method instead of rewriting same code• Allows us to think at higher level– Think “surprise” instead of “alien moves up, alien says something, robot turns around…”– Technical term for “think at a higher level” is abstractionWorld.myFirstMethod now• Move robot forward twice as far by invoking “investigate” twiceClasswork today• Modify snowpeople to add two methods– catchAttention– fliphats• Create airport/helicopter world with new method–


View Full Document

Duke CPS 004 - Chap 4 Sec 1

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 Chap 4 Sec 1
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 Chap 4 Sec 1 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 Chap 4 Sec 1 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?