1 / 34

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.

gamma
Download Presentation

Lecture 3: Chapter 4.1 and 4.2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  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

  3. How to Do Homework • Don’t read FIRST • Sit down, open Alice, and do the homework WHILE you are using Alice.

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

  5. 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”

  6. 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… More about this next week! * http://money.cnn.com/2012/01/16/technology/sopa_wikipedia/index.htm

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

  8. What term do we use to describe the indicated area below A. Method call B. Method definition C. Method action

  9. 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 parameter

  10. 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 corner

  11. Ways to demonstrate understanding of programming Writing Reading • Communication among people • Debugging • Produce a result/artifact

  12. 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 

  13. 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 above

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

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

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

  17. Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods 4.2 Parameters (up to page 107)

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

  19. 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 say

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

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

  22. 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 correct

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

  24. 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 correct

  25. 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 C

  26. 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 programs

  27. 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 C

  28. 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 programs

  29. Underline the parameters in the following method call

  30. Just vocabulary: Parameters • Always come “after” the method name on a tile

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

  32. What does this do?

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

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

More Related