Presentation is loading. Please wait.

Presentation is loading. Please wait.

Don Slater Wanda Dann

Similar presentations


Presentation on theme: "Don Slater Wanda Dann"— Presentation transcript:

1 Don Slater dslater@andrew.cmu.edu Wanda Dann wpdann@andrew.cmu.edu

2 Recall: Step 3 Write statements (code) – a few steps at a time, not the entire program at once! Problem Statement Understand the problem Implement the design Test the code Design a solution Decompose into simple steps

3 Recall: we created a statement  A statement is created by dragging a code tile into the edit space

4 Penguin moves toward the ball  However…..  Where is the swagger? Do in order penguin swagger penguin pushes the bowling ball so it rolls to the pin pin falls over pin responds (stands up and pushes the ball back to penguin) penguin falls over

5 Built-in procedures are simple actions. The penguin doesn’t have a swagger procedural method -- swagger is a complex action that combines several simple actions. Built-in procedures

6 Decomposition of swagger penguin swagger Do in order // penguin shift side to side penguin roll left 0.125 penguin roll right 0.25 penguin roll left 0.125 // penguin jump up and down penguin moves up 0.5 penguin moves down 0.5 Do in order penguin swagger penguin pushes the bowling ball so it rolls to the pin pin falls over pin responds (stands up and pushes the ball back to penguin) penguin falls over

7  Procedural methods (actions for objects) are declared & defined in the class 1. Select Penguin from Class Menu in the Code Editor 2. From the Penguin sub-menu, select Add Procedure… Creating your own procedure

8 3. Type in a name for the new procedure  Naming rules ◦ Begin with an alphabetic character, not a digit ◦ A name consists of letters, digits or underscore “_”, no spaces or other symbols ◦ Naming conventions ◦ Start with a lower case letter ◦ Use camelCase if more than one word is desired

9 Procedure names in Different Classes Two or more classes may have procedural methods that have the same name Penguin has a swagger Pin may also have a swagger Even though the names may be the same, the actions performed may be different Example Penguin swagger is side to side Pin swagger might be front to back

10 Procedure swagger

11 this  “this” is a proxy – “stands in for” the name of any penguin object (instance of the Penguin class) in your scene

12  The class tab shows all the methods (procedures & functions) and properties of the class 2. Possible to add or edit procedures, functions, or properties to this class Class tab

13 Documentation for procedures – Assumes: Assumptions made regarding conditions prior to calling the procedure – Action: description of the procedure action – Postcondition, if any

14 More specific comments may be imbedded in the code, to help other programmers understand what the code is intended to do In-line Comments

15  Using our design as a guide, drag tiles into the swagger code editor. Implement swagger penguin swagger Do in order // penguin shift side to side penguin roll left 0.125 penguin roll right 0.25 penguin roll left 0.125 // penguin jump up and down penguin move up 0.5 penguin move down 0.5

16

17 Step 4: Test Problem Statement Understand the problem Implement the design Test the code Design a solution Does it work, no matter what? Try different values (distance, direction, revs)

18 Test Click on Run button Return to Scene class

19 What happens? Nothing!!! Why?

20 Call swagger in myFirstMethod Now, we need to call it somewhere in our program 1.Select penny in the instance menu 2.Drag the swagger tile into myFirstMethod in the editor We defined the new procedure, swagger 1. 2.

21 Test again We should see the penguin swagger


Download ppt "Don Slater Wanda Dann"

Similar presentations


Ads by Google