Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.

Similar presentations


Presentation on theme: "Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition."— Presentation transcript:

1 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition by Tony Gaddis Chapter 4: Programming in Alice

2 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-2 Chapter 4 Objectives To understand: –method naming conventions –what dot notation is –what a primitive method is and which objects have them –what is meant by “calling” –what an argument is in a program. –differences in naming conventions –the steps of the program development cycle –what a logical error is –the need for commenting

3 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-3 Today’s Agenda 1.Writing Methods 2.Naming Conventions 3.Designing a Program 4.Comments 5.Tips for Setting Up an Initial Scene 6.Executing Instructions Simultaneously 7.Exporting Your Code for Printing

4 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-4 Writing Methods What is a method? –set of instructions that execute –create methods by dragging tiles into the Method Editor –these tiles are the instructions my first method 2.1

5 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-5 Naming Conventions dot notation –world.my first method dot (period) separates pieces of information –left side: object that the method belongs to in this case…the method belongs to the WORLD object –right side: name of the method in this case… “my first method” the period is called a “dot” 2.1

6 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-6 world.my first method Events Editor identifies which method plays or is acted upon when the “Play” button is hit 2.1

7 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-7 world.my first method Methods play the instructions (tiles) that are dragged into the Method Editor 2.1

8 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-8 Primitive Methods All objects have a common set of built-in method for performing actions. These “primitive methods” all objects to move, turn, change size, and more. Example: Hare has primitive methods to move, turn, roll, resize, say dot notation: hare.move 2.1

9 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-9 Terminology Calling the method: –executing a method Argument: –piece of information that a method needs in order for it to execute –hare.move…which direction? the direction…up, down, left, right…is the argument Passing the Argument: –the method is called and the arguments are presented objec t method argument editing tag 2.1

10 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-10 Editing Tag Holds additional arguments What appears depends on the method called –duration specifies amount of time for action to take place default (1 second) 2.1

11 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-11 Deleting Right-click the instruction and select delete Drag the instruction tile to the trash can 2.1

12 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-12 Copying Right-click the instruction and select copy Drag the instruction tile to the clipboard –when the clipboard turns green, drop the tile –click on the clipboard and drag it back to the Method Editor 2.1

13 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Custom Methods In addition to primitive methods (the things that ALL objects can do)…some objects have custom methods When objects is selected from gallery, a listing of custom methods appears Names of the custom methods give clues as to what the method does What do you think the foottap custom method does? 2.1

14 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-14 namingConventions Names are known as identifiers…because they identify items in a program Use a name that provides meaning –Name of method should indicate the method’s purpose 2.2 Which one coaches the Knights and which one coaches the Cougars?

15 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-15 namingConventions Most programming languages do NOT recognize spaces –Alice allows spaces method.my first method Since spaces are not allowed, how do you combine more than one word in naming? –Capitalize subsequent words –Called camelCase 2.2 Note the space Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Which is easier to read? onehumpcamel or oneHumpCamel

16 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-16 Class Names method names begin with a lower case letter Class names are capitalized No spaces, so each word is capitalized –This convention is called PascalCase 2.2

17 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-17 Renaming Objects –Right-click object’s tile in the object tree and select rename. Methods –Select the world object –Select the method’s tab from the Details Panel –Right-click the my first method tile and select rename. 2.2

18 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-18 Designing a Program Design requires planning…that follows the above steps Called program development cycle Cycle is repeated until there NO errors appear in the program. 2.3 Design the programWrite the methodsTest the methodsDebug the methods

19 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-19 Designing the Program Determine what the world is supposed to do. Use problem statement that describes the objects that will appear 2.3 Design the programWrite the methodsTest the methodsDebug the methods

20 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-20 Designing the Program Break the problem statement down into series of steps –Pseudocode –Flowchart 2.3 Design the programWrite the methodsTest the methodsDebug the methods

21 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-21 Writing the methods Design steps (pseudocode or flowchart) provides model for writing the methods Drag tiles into Method Editor to assemble instructions Instructions should follow the order of the Design steps Pseudocode and flowchart may NOT be at the detail of the final instructions 2.3 Design the programWrite the methodsTest the methodsDebug the methods

22 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-22 Testing Test to make sure it meets the following criteria: –Does it do what it was intended to do? –Does it have any errors? Or undesired results? –Is it efficient? Are there unnecessary steps? If the criteria are NOT met, then debugging occurs Debugging means to determine what must be corrected or modified to get the program to work correctly. 2.3 Design the programWrite the methodsTest the methodsDebug the methods

23 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-23 Designing a Program Debugging means to determine what must be corrected or modified to get the program to work correctly Logical errors (bug) is a mistake that produces an incorrect result, but the program still runs. –Instructions in an incorrect order may produce incorrect results –Passing incorrect values as arguments can cause logical errors 2.3 Design the programWrite the methodsTest the methodsDebug the methods

24 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-24 Comments A comment is a note explaining the code Crucial part of the code Makes the code understandable Alice ignores comments when it plays your program 2.4 // comment tile

25 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-25 Tips for Setting Up the Initial Scene Use the primitive methods to setup the scene –Select the object in the Object Tree, then select a method Use the primitive methods to position the objects –Doing so from the Object Tree positions the objects outside of the program 2.5

26 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-26 Tips for Setting Up the Initial Scene Moving an object to the center of the world –Use the move to method and choose the entire world as the method’s argument –Places the object’s center point at the world’s center point of (0, 0, 0) 2.5

27 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-27 Tips for Setting Up the Initial Scene Positioning objects a specified distance apart –Use the move to method and choose asSeenBy the other object for the method’s argument –Places the object’s center point at the world’s center point of (0, 0, 0) 2.5

28 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-28 Tips for Setting Up the Initial Scene Moving the camera to an object –Right-click the object and choose Camera get a good look at this –Camera moves to a position so the object is in plain view 2.5

29 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-29 Executing Instructions Simultaneously By default, instructions are executed one after the order…in the order they appear in the Methods Editor For simultaneous actions, drag Do together into the Methods Editor Other instructions can be place within the Do together tile Make sure the duration for all items in Do together are the same 2.6

30 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-30 The Do in order Structure By default, all instructions are performed in order they appear in the Methods Editor Do in order structure used when more than one set of actions must occur simultaneously…but has steps that must be done in order 2.6

31 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-31 Exporting Code for Printing Code can be exported to an HTML file –Open the file and Print From File – Choose Export Code for Printing YOU must add your name as the author –Author’s name is printed with the exported code 2.7 Author’s name


Download ppt "Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition."

Similar presentations


Ads by Google