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

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

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

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 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 2-2 my first method 2.1

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 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” 2-3 the period is called a “dot” 2.1

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley world.my first method Events Editor identifies which method plays or is acted upon when the “Play” button is hit An Error might appear if this section is blank. 2-4 2.1

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

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 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 2-6 dot notation: hare.move 2.1

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Tutorial Design Practicing Using Methods Create Tutorial 2-1 on pages 62-64 2-7

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 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 2-8 object method argument editing tag 2.1

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 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-9 2.1

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

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 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-11 2.1

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Primitive Methods Task Complete the Exploring Primitive Methods tutorial(2-2) on page 67-69 Add three other enhancements to the scene. 2-12

Copyright © 2012 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

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Naming Conventions 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-14 2.2 Which one coaches the Knights and which one coaches the Cougars?

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

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 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-16 2.2

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 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-17 2.2

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 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-18 2.3 Design the programWrite the methodsTest the methodsDebug the methods

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

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

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 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-21 2.3 Design the program Write the methods Test the methodsDebug the methods

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 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-22 2.3 Design the programWrite the methods Test the methods Debug the methods

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 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-23 2.3 Design the programWrite the methodsTest the methods Debug the methods

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Using The Program Design Cycle Pay close attention to the instructions along with the problem statement, flowchart and pseudocode found on pages 82-83 before jumping straight into the program. Complete Using the program design cycle tutorial(2-3) on page 82-87 2-24

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Custom Program Design Task Students will design a flowchart or pseudocode that will include at least twenty different changes within a program of his/her choosing. -After the flowchart or the pseudocode have been approved students should design the program within Alice by taking the flowchart or the pseudocode and turning them into functional parts within a program. Example 1 Change : White Rabbit moves forward to a position in front of the car 2-25

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Comments 2-26 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

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Tips for Setting Up the Initial Scene 2-28 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

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Cinderella Needs Our Help Look at pages 93 and 94. Insert a new Cinderella Object Perform the three steps on pages 93 and 94 to move Cinderella's hands to her side using methods. 2-29

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 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-30 2.5

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 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-31 2.5

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 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-32 2.5

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 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-33 2.6

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 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-34 2.6

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Loops Complete the tutorial 2-5 on pages 98-102 to reinforce the concept of looping within Alice. 2-35

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Exporting Code for Printing 2-36 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

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Exporting an Alice World to Video An Alice world can be exported to video and shared with others on the Internet Open the File menu and select Export Video You are required to save your world by clicking the Save button Click the Record button to start recording and the Stop Recording button when you are finished Name your video and click the Export Video button Video will be created in the same location where you saved the Alice world 2-37

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Challenge Yourself Students will complete three basic skills program and one challenge program from the exercises at the end of the textbook. Students will choose three(50 points each) of the following to complete from pages 109 – 111. -Exercise 1,3,5,6,10 Students should choose one(100 points) of the following challenge programs 8,9 or 12 2-38

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Skills Test Students will complete exercise 11 from page 111. - Students will select a scene from their favorite movie(school appropriate) and then use Alice to recreate the scene with the dialog, sound and movement from the movie. -Students will have 4 days to complete the design of the movie scene. -The movie scene will count as a proficiency measure grade(100 point test grade). -An algorithm or flow chart will be required to outline the scene otherwise the scene will not be accepted for a grade. 2-39