Presentation is loading. Please wait.

Presentation is loading. Please wait.

Implementation with procedural methods. Recall: Step 3 Write statements (code) – a few steps at a time, not the entire program at once! Problem Statement.

Similar presentations


Presentation on theme: "Implementation with procedural methods. Recall: Step 3 Write statements (code) – a few steps at a time, not the entire program at once! Problem Statement."— Presentation transcript:

1 Implementation with procedural methods

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 Do in order penguin move forward (to the ball) 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 Penguin swagger  Where is the swagger?

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 move up 0.5 penguin move down 0.5 Do in order penguin move forward (to the ball) 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 1. Select Penguin from Class Menu 2. Select the Penguin class tab Open class tab 1 2

8  The class document shows all the methods (procedures & functions) and properties of the class Can add, edit, or delete procedures, functions, or properties in a class document Class tab

9 Click the Add Procedure button… in the procedures section Add a procedure

10 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

11 Procedure names in classes Two or more classes may have procedural methods that have the same name Penguin has a swagger Pin might 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

12 Procedure swagger

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

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

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

16  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

17

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

19 Test Click on Run button Return to Scene class

20 What happens? Nothing!!! Why?

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

22 Test again We should see the penguin swagger

23 1. Click on the Class Menu button 2. Select Penguin from Class Menu in the Code Editor 3. Select Add Procedure… from the Penguin class submenu Start by clicking here Hint: Quick access to Add procedure button 2 3 1


Download ppt "Implementation with procedural methods. Recall: Step 3 Write statements (code) – a few steps at a time, not the entire program at once! Problem Statement."

Similar presentations


Ads by Google