/
Lecture 3: Chapter 4.1 and 4.2 Lecture 3: Chapter 4.1 and 4.2

Lecture 3: Chapter 4.1 and 4.2 - PowerPoint Presentation

phoebe-click
phoebe-click . @phoebe-click
Follow
363 views
Uploaded On 2016-04-03

Lecture 3: Chapter 4.1 and 4.2 - PPT Presentation

Discussion groups Very impressed Excellent job by classwide discussion contributors Learning Goal Technical analysis and communication skills Coaches help you ask yourselves the right questions ID: 273420

parameter method

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Lecture 3: Chapter 4.1 and 4.2" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Lecture 3: Chapter 4.1 and 4.2

Discussion groups: Very impressed!

Excellent job by class-wide discussion contributors

Learning Goal: Technical analysis and communication skills

Coaches help you “ask yourselves the right questions”

Meet the CoachesSlide2

Click in every time!

Or you are losing points!

Quiz Questions:

No negative points for wrong answer, try!

Discussion Questions:

You need to get >=50% of questions correct!

Reward for preparing for class

B

eing able to develop your analysis and communication skills

And you and your group must all

CHOOSE THE SAME ANSWER

after discussion

Encourage “good” and thorough discussionsSlide3

How to Do Homework

Don’t read FIRST

Sit down, open Alice, and do the homework WHILE you are using Alice.Slide4

What do you get from this course?

Analysis skills –

Practiced and refined in your group discussions!

We learned in Alice that computers do exactly what you have them do.  

Using this knowledge, we can understand how programs like Excel and Numbers work

and learn that when we are using these programs,

we need to specify and be exact

with what we are doing in order for the programs to meet our needs and plans

.Slide5

Analysis Technique:

Begin at the beginning:

Are you reading the question the “same way”?

What is the question asking for?

TRY THESE:

“So what I think this is asking is”

“It seems like the idea here is whether we can identify the differences in these codes”

“We need to figure out how to correct this code to do X instead of Y”Slide6

Another reason this class is important

From CNN article* on SOPA – Stop Online Piracy Act

“But

SOPA's critics say that say that the bill's backers don't understand the Internet, and therefore don't appreciate the implications of the legislation they're considering

.”

The “basic” view

If your site links to a site which links to a site that might have pirated content…

* http://

money.cnn.com

/2012/01/16/technology/

sopa_wikipedia

/

index.htm

More about this next week!Slide7

What is the best explanation of why we divide

code

into methods?

In order to be able to put a name on them

In order to break work into manageable pieces

So it can be stored more efficiently

So that each object can have “actions” they doSlide8

What term do we use to describe the indicated area below

A. Method call B. Method definition

C. Method actionSlide9

If you created a new band member (“Juan” Beetle)

would you need to create a new method to get him to play a solo?

Yes, you would need to make a copy where

juan’s

object would call methods

Yes, because otherwise

juan

wouldn’t know what to do

No, you wouldn’t be able to get him to play a solo – this would only work for 4 beetles

No, you can use the same method, passing in the

juan

beetle as a parameterSlide10

When you hit Play Alice will by default*:

Runs

World.My

first method

Starts by running whatever method you created first

Starts by running whatever method you created last

Runs all the methods in the order they appear in the methods tab

None of the above

*Assuming you don’t modify any of the events in the upper right cornerSlide11

Ways to demonstrate

understanding of programming

Scenario: Idea in

your head

Design: Storyboard

Implementation: Program

Writing

Reading

Produce a result/artifact

Communication among people

DebuggingSlide12

That was Writing, Now Reading

Given an Alice program (or part of a program)

Be able to read it and describe what code does (scenario)

In English, since we’re not making you draw or even give the storyboard

Slide13

What does this code do?

Makes the

eskimo

girl say Hello, then jump up and down

Makes the

eskimo

girl say Hello WHILE jumping up and down

Makes the

eskimo

girl say Hello

None of the aboveSlide14

How would we change the code to make her say Hello while jumping up and down?Slide15

Note: Our intent in NOT to “trick you”

Computer programs are

PICKY

Getting them to do what you want requires paying attention to a lot detail

In computing, getting the computer to do EXACTLY what you want is often very important

Flying planes:

A BIT too close is TOO CLOSE!

Red light cameras better not ticket me when the light’s yellowSlide16

Methods you might like to use

(and you should play with)

move

vs

turn

vs

roll

The “as Seen By” modifier

Can make moving, turning or rolling behave differently

OrientTo

PointAt

Duration and Style modifiers (abruptly, etc.)Slide17

Chapter 4: Classes, Objects, and Parameters

4.1 World-Level methods

4.2 Parameters (up to page 107)Slide18

Did you watch the 8-min video?

You need to know

Step-wise refinement

How to decide what to put in a method

Who methods “benefit”

Various benefits of methods

Easy to repeat (or re-order) workSlide19

Below: what happens after the last instruction in the mystery method is finished executing?

The program starts the World.my first method

The program goes back to my first method and calls method XXXXX

The program goes back

to my first method and calls method YYYYY

We can’t tell, we need to know more about the storyboard to be able to saySlide20

Methods: Why again?

Break complex things into smaller, more manageable pieces (step-wise refinement)

Do something more than once…

Do something more than once, but not exactly the same each time

Parameters

allow you to write code one time but have it be useful in various circumstances

where the “thing” involved could be different each timeSlide21

Parameters: Controlling variation

We wanted to make the beetles be able to do identical solos

But we didn’t want to have to write it out 4 times.

So we passed a parameter that told which beetle to move

The challenging issue is often figuring out what parameters a given method could haveSlide22

If we write a method called drive, which would not make sense as a parameter to control how drive occurs?

Destination

How fast

Which car

Car color

*Green ringed slides: exploratory – any answer will “count as” correct

Even though some ARE NOT correctSlide23

If we write a method called drive, which would not make sense as a parameter to control how drive occurs?

Destination

How fast

Which car

Car colorSlide24

If we write a method called

beat

(as in a cooking context) which would not make sense as a parameter

Temperature of ingredients

How long

Finishing state (soft/medium/hard peaks)

Ingredients to beat

Container to use

*Green ringed slides: exploratory – any answer will “count as” correct

Even though some ARE NOT correctSlide25

A parameter

Has a “type” such as a Number, Object, or Other (e.g. Color, Sound)

Is something you must have for every method

Allows you to send information to a method when it is called

A and B

A and CSlide26

Which of the following is the

best explanation

of what makes a good parameter

It’s something that supports common variation in how the method is done

It’s got a meaningful name

It can be either an Object or a number

It’s helps manage complexity in large programsSlide27

A parameter

Has a “type” such as a Number, Object, or Other (e.g. Color, Sound)

Is something you must have for every method

Allows you to send information to a method when it is called

A and B

A and CSlide28

Which of the following is the

best explanation

of what makes a good parameter

It’s something that supports common variation in how the method is done

It’s got a meaningful name

It can be either an Object or a number

It’s helps manage complexity in large programsSlide29

Underline the parameters in the following method call

1

2

3

4

5

A)

X

X

X

X

B)

X

X

X

X

C)

X

X

X

D)

X

XSlide30

Just vocabulary: Parameters

Always come “after” the method name on a tileSlide31

Alice: It’s REALLY close to Java

(and most every programming language today)

public class Demo

{

public static void main (String[]

args

)

{

World w = new World("Chapter04Example

");

//

x, y, and z coordinates

)

Skater

iceSkater

= new Skater(w, 100, 200, 0);

iceskater.move

("forward", .5, 2

);

//

where 0 is forward, 1: backward,

2:left,etc.

//

iceskater.move

(0, .5, 2);

}

}Slide32

What does this do?Slide33

How did it go?

Did you get 50% right?

Yeah, you might need to read more

Slowly

Deeply (?)

Do the

homeworks

With someone else

Talk about them with someone else (or me!)Slide34

Which best describes what happens when my First Method is run?

The helicopter moves down to the rabbit’s location

The rabbit moves up to the helicopter’s location

The helicopter and the rabbit move to meet each other (halfway between)

I don’t know