lecture 3: chapter 4.1 and 4.2

34
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 Coaches

Upload: gamma

Post on 22-Feb-2016

54 views

Category:

Documents


0 download

DESCRIPTION

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 Coaches. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Lecture 3: Chapter 4.1 and 4.2

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 Coaches

Page 2: Lecture 3: Chapter 4.1 and 4.2

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• Being 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 discussions

Page 3: Lecture 3: Chapter 4.1 and 4.2

How to Do Homework

• Don’t read FIRST• Sit down, open Alice, and do the homework

WHILE you are using Alice.

Page 4: Lecture 3: Chapter 4.1 and 4.2

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.

Page 5: Lecture 3: Chapter 4.1 and 4.2

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”

Page 6: Lecture 3: Chapter 4.1 and 4.2

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!

Page 7: Lecture 3: Chapter 4.1 and 4.2

What is the best explanation of why we divide code into methods?

A. In order to be able to put a name on themB. In order to break work into manageable

piecesC. So it can be stored more efficientlyD. So that each object can have “actions” they

do

Page 8: Lecture 3: Chapter 4.1 and 4.2

What term do we use to describe the indicated area below

A. Method call B. Method definitionC. Method action

Page 9: Lecture 3: Chapter 4.1 and 4.2

If you created a new band member (“Juan” Beetle) would you need to create a new method to get him to

play a solo?

A. Yes, you would need to make a copy where juan’s object would call methods

B. Yes, because otherwise juan wouldn’t know what to do

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

D. No, you can use the same method, passing in the juan beetle as a parameter

Page 10: Lecture 3: Chapter 4.1 and 4.2

When you hit Play Alice will by default*:

A. Runs World.My first methodB. Starts by running whatever method you

created firstC. Starts by running whatever method you

created lastD. Runs all the methods in the order they

appear in the methods tabE. None of the above

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

Page 11: Lecture 3: Chapter 4.1 and 4.2

Ways to demonstrate understanding of programming

Scenario: Idea in your head

Design: Storyboard

Implementation: Program

Writing

Read

ing

• Produce a result/artifact • Communication among people• Debugging

Page 12: Lecture 3: Chapter 4.1 and 4.2

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

Page 13: Lecture 3: Chapter 4.1 and 4.2

What does this code do?

A. Makes the eskimo girl say Hello, then jump up and down

B. Makes the eskimo girl say Hello WHILE jumping up and down

C. Makes the eskimo girl say HelloD. None of the above

Page 14: Lecture 3: Chapter 4.1 and 4.2

How would we change the code to make her say

Hello while jumping up and

down?

Page 15: Lecture 3: Chapter 4.1 and 4.2

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

yellow

Page 16: Lecture 3: Chapter 4.1 and 4.2

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.)

Page 17: Lecture 3: Chapter 4.1 and 4.2

Chapter 4: Classes, Objects, and Parameters

4.1 World-Level methods4.2 Parameters (up to page 107)

Page 18: Lecture 3: Chapter 4.1 and 4.2

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) work

Page 19: Lecture 3: Chapter 4.1 and 4.2

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

A. The program starts the World.my first methodB. The program goes back to my first method and calls

method XXXXXC. The program goes back to my first method and calls

method YYYYYD. We can’t tell, we need to know more about the

storyboard to be able to say

Page 20: Lecture 3: Chapter 4.1 and 4.2

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 time

Page 21: Lecture 3: Chapter 4.1 and 4.2

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 have

Page 22: Lecture 3: Chapter 4.1 and 4.2

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

A. DestinationB. How fastC. Which carD. Car color

*Green ringed slides: exploratory – any answer will “count as” correctEven though some ARE NOT correct

Page 23: Lecture 3: Chapter 4.1 and 4.2

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

A. DestinationB. How fastC. Which carD. Car color

Page 24: Lecture 3: Chapter 4.1 and 4.2

If we write a method called beat (as in a cooking context) which would not make sense as a parameter

A. Temperature of ingredientsB. How longC. Finishing state (soft/medium/hard peaks)D. Ingredients to beatE. Container to use

*Green ringed slides: exploratory – any answer will “count as” correctEven though some ARE NOT correct

Page 25: Lecture 3: Chapter 4.1 and 4.2

A parameter

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

B. Is something you must have for every method

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

D. A and BE. A and C

Page 26: Lecture 3: Chapter 4.1 and 4.2

Which of the following is the best explanation of what makes a good parameter

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

B. It’s got a meaningful nameC. It can be either an Object or a numberD. It’s helps manage complexity in large

programs

Page 27: Lecture 3: Chapter 4.1 and 4.2

A parameter

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

B. Is something you must have for every method

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

D. A and BE. A and C

Page 28: Lecture 3: Chapter 4.1 and 4.2

Which of the following is the best explanation of what makes a good parameter

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

B. It’s got a meaningful nameC. It can be either an Object or a numberD. It’s helps manage complexity in large

programs

Page 29: Lecture 3: Chapter 4.1 and 4.2

Underline the parameters in the following method call

1 2 3 4 5A) X X X X

B) X X X X

C) X X X

D) X X

Page 30: Lecture 3: Chapter 4.1 and 4.2

Just vocabulary: Parameters

• Always come “after” the method name on a tile

Page 31: Lecture 3: Chapter 4.1 and 4.2

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); }}

Page 32: Lecture 3: Chapter 4.1 and 4.2

What does this do?

Page 33: Lecture 3: Chapter 4.1 and 4.2

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!)

Page 34: Lecture 3: Chapter 4.1 and 4.2

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

A. The helicopter moves down to the rabbit’s location

B. The rabbit moves up to the helicopter’s location

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

D. I don’t know