DOC PREVIEW
Duke CPS 004 - Chap 4 Sec 3 – Part 2

This preview shows page 1-2 out of 5 pages.

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

Unformatted text preview:

CompSci 4Chap 4 Sec 3 – Part 2Feb 17, 2005Prof. Susan RodgerNote: thanks to Wanda Dann and Steve Cooper for slide ideasAnnouncements• Read Chapter 5.1 for next time• Assignment 5 out today• Prof Rodger – extra office hours friday, no office hours next week!What we will do today• Lecture on Chap 4 Sec 3 (continued)• ClassworkGuidelines• To avoid misuse of class level methods– Avoid references to other objects– Avoid calls to world-level methods– Play a sound only if the sound has been imported and saved out as part of the new class• If these guidelines are not followed and an instance of the new class is added to another world– Alice will open an Error dialog box to tell you something is wrongBad Example 1Bad Example 2Problem• What if you were convinced you needed to write a class-level method where another object is involved?• For example, a method for ice skater to skate around another object – here a penguinSolution• Class-level method with object parametercleverSkater.skateAroundParameter: whichObjectDo in orderDo togethercleverSkater turn to face whichObjectcleverSkater lift right legcleverSkater move to whichObjectcleverSkater turn around whichObjectTranslating Design into Code• Most of skateAround storyboard easy to code• Last two steps, require more thought– cleverSkater move to whichObject• What distance should cleverSkater move?– cleverSkater turn around whichObject• How do we tell cleverSkater to turn (in a circle) around another object?Built-in Functions (or questions)• The built-in function distance to– used to determine the distance the skater must moveCalling the function• Code to move skater to whichObjectOops, skater will collide with penguin!Distance between two objects ismeasured center-to-centerExpressions• To avoid collision– Use math operator to create an expression that adjusts the distance• Math operators in Aliceaddition + subtraction -multiplication * division /•Example:How to put in an Expression2 3 1 4 Result:ResultStops before penguin Skates around penguinasSeenBy• For skater to skate around another object–Pass whichObject as an argument to asSeenBy parameter in turn instructionMore on AsSeenBy• Use invisible object (isShowing set to false) to have objects fly around in a circleTesting• Each time you create a new class, test it!– Add an instance of new class to new world– Write a short test program • Test each new method• Testing increases your confidence in the ability to reuse your code in other worldsClasswork today• Modify your two classes from last time– Add methods with parameters– Use asSeenBy– Use isShowing– Use math• Create a new world with 3 objects and demo• See handout for more


View Full Document

Duke CPS 004 - Chap 4 Sec 3 – Part 2

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 3 – Part 2
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 3 – Part 2 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 3 – Part 2 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?