Class 5 - Variables and Functions, continued Matthew Hashim...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
12/4/09 Click to edit Master subtitle style Variables and Functions, continued Matthew Hashim 9/8/2009 11
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
MGMT 290D 12/4/09 Goals for Today n Use parameters to write methods that are more broadly useful n Define and access property variables n Use the vehicle property to synchronize the movements of two objects n Create functions — messages that return a value to their sender 22
Background image of page 2
MGMT 290D 12/4/09 Parameters n Argument: value passed to an object via a message n Parameter: variable that stores an argument n Example using the say() message ¨ The parameter is a single variable of String type ¨ One possible argument is “Oh, hello there!” n You may pass multiple arguments to messages ¨ Example: roll() message requires two arguments 33
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
MGMT 290D 12/4/09 Example 1: Old MacDonald Had a Farm n Objective: display song lyrics for four animals n Use of parameters helps avoid repetitious coding n Two parameters needed: animal and noise n Overview of implementation ¨ Create new world with scarecrow before fence ¨ Create singVerse() method for scarecrow ¨ Add two parameters, animal and noise ¨ Add String types, firstLine and doubleNoise ¨ Incorporate parameters and variables in say() methods ¨ Call singVerse() messages in singOldMacDonald() 44
Background image of page 4
MGMT 290D 12/4/09 Example 1: Old MacDonald Had a Farm (continued) 55
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
MGMT 290D 12/4/09 Example 1: Old MacDonald Had a Farm (continued) 66
Background image of page 6
MGMT 290D 12/4/09 Example 1: Old MacDonald Had a Farm (continued) 77
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
MGMT 290D 12/4/09 Example 2: Jumping Fish! n User story: fish jumps, traces an arc, returns to water n Fish object used is an instance of Pinkminnow n Basic elements in the design of jump() method ¨ One parameter: distance ¨ Local var: height , halfDist , startStopDist , angle
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/04/2009 for the course MGMT 290 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 31

Class 5 - Variables and Functions, continued Matthew Hashim...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online