Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/http://creativecommons.org/licenses/by-nc-

Similar presentations


Presentation on theme: "Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/http://creativecommons.org/licenses/by-nc-"— Presentation transcript:

1 Creative Commons Attribution Non-Commercial Share Alike License http://creativecommons.org/licenses/by-nc- sa/3.0/http://creativecommons.org/licenses/by-nc- sa/3.0/ Original Developer: Beth Simon, 2009 bsimon@cs.ucsd.edu

2 CSE8A Lecture 4 TURN IN INTEGRITY FORMS NOW! (up front) SIT WITH YOUR DISCUSSION GROUP for the QUIZ –Come to the front if you don’t know where they are TODO: –Work on PSA1 WITH YOUR PARTNER! Expect to spend 6 hours! If you don’t have a partner by after class, do this PSA on your own Read next class: pages 90-117, take the online reading quiz. CLICKERS OUT! LAPTOPS? http://up.ucsd.edu

3 Quiz: 2 parts Do once, by yourself. (8-10 min) –Closed book –No calculator –No notes Turn in (pass to aisle) In TEAM (2-5 people max), complete ONE together (5 min) –Put all your names on it –Discuss the answers with each other Why is one answer right, why are the other answers wrong?

4 By the end of today’s class you should be able to… LG7: Know which methods get stored in Turtle.java and which get stored in their own files (and why). LG8: Describe return values of methods and identify ones from methods you have used LG9: Nest several method calls in one statement (in contrast to doing multiple assignments) LG10: Explain how bits (0s and 1s) in a computer’s memory can be interpreted in a variety of ways (depending on issues of type and representation)

5 Storing methods in the correct file We just wrote 2 methods. They each have to be stored in a different place. bethsSquare is a method that can be called on a Turtle so it needs to be in the Turtle class ( Turtle.java ) –t.bethsSquare(50); Then we wrote code to “test out” our Turtle method to “act on” a specific turtle. –That needs to go in a method that we can make up a name for… like SpecialTester.java

6 For PSA3: Where are files stored and WHY? 1) drawShape –A method which acts on a turtle object to make it complete a set of steps to make a closed form shape of your choosing 2) createShapes –Directs 4 different turtles in calling the drawShape method to make 4 nested copies of your shape

7 Writing Methods: Rules and Why Methods are a way of “encapsulating” (putting together in one place/one name) a series of code statements. They are “wrapped” in their –Method header (visibility, return type, name, parameter list) –And { and } enclose all the statements that we want to have done when we “call” that method WHY? –We do this when we have a set of statements that we may want to have done multiple times (and possibly for multiple objects/turtles)

8 Why Do Methods Get Stored in Turtle.java? If a method describes a “general action” a turtle could reasonably be expected to do –It goes in the Turtle class If it’s a specific “application” that is just a “one off” need –It’s its own program (createShapes, myWackyTurtleProgram, etc) Classes (like Turtle and Picture) are made up of –Data about them –Methods/Actions that can be taken on them

9 Pictures! DEMO You can’t learn to program by reading about it –PLAY! You NEED TO try typing in the code to (for Pictures) –Create –Show –Open –Explore

10 What types are returned by these method calls? A) main main Picture String B) Turtle Turtle Picture String 1)SOLO VOTE (60 sec) 2)Discuss in team (2 min) 3)GROUP VOTE (30 sec) 1) turtle1.turnLeft(); 2) turtle1.getName(); 3) FileChooser.pickAFile(); 4) new Picture(); B) void void Picture String C) void void String Picture E) None Of The Above

11 What is a return value?


Download ppt "Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/http://creativecommons.org/licenses/by-nc-"

Similar presentations


Ads by Google