Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 2: Programming in Alice

Similar presentations


Presentation on theme: "Chapter 2: Programming in Alice"— Presentation transcript:

1 Chapter 2: Programming in Alice

2 Chapter 2 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 Lessons Writing Methods Naming Conventions Designing a Program
Comments Tips for Setting Up an Initial Scene Executing Instructions Simultaneously Exporting Your Code for Printing

4 2.1 Writing Methods In chapter 1 we learned the basics of placing objects in an Alice world and then manipulated the way those objects appear. The worlds did not perform any actions. If we want the objects in an Alice world to perform actions, we have to write a program.

5 Writing Methods What is a method? set of instructions that execute
2.1 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

6 the period is called a “dot”
2.1 Naming Conventions All methods have a name. 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”

7 2.1 world.my first method Events Editor identifies which method plays or is acted upon when the “Play” button is hit

8 tile world.my first method
2.1 world.my first method Methods play the instructions (tiles) that are dragged into the Method Editor Each tile represents an action that will take place when the world is played. tile

9 2.1 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: move, turn, roll, resize, say, … Name of object.Name of method

10 Adding a Method to a Program
2.1 Adding a Method to a Program Highlight the object, drag and drop the method into the Method Editor, select the arguments.

11 Adding a Method to a Program
2.1 Adding a Method to a Program Or Right click on the object, choose the methods menu, choose the method from the list, choose the arguments

12 Terminology argument argument method object editing tag
2.1 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 argument argument method object editing tag

13 Editing Tag Holds additional arguments
2.1 Editing Tag Holds additional arguments What appears depends on the method called duration is a common one specifies amount of time for action to take place default (1 second)

14 Table 2-1 summarizes all the primitive methods.
2.1 Table 2-1 summarizes all the primitive methods. orient to turn to face point at set point of view to set pose stand up move at speed turn at speed roll at speed constrain to face constrain to point at move turn roll resize say think play sound move to move toward move away from

15 Deleting Instructions
2.1 Deleting Instructions Right-click the instruction and select delete or Drag the instruction tile to the trash can

16 Copying Instructions Right-click the instruction and select copy
2.1 Copying Instructions 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

17 2.1 Custom Methods In addition to primitive methods (the things that ALL objects can do)…some objects have custom methods Custom methods are methods that only objects of a specific class can do. 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?

18 2.1 Custom Methods When you add an object and then select that object, tiles representing its custom methods (if it has any) appear above the tiles for the primitive methods in the Details Panel.

19 2.1 p. 62 Tutorial 2-1 Happy Hare aka Hare jumps up then down.

20 p. 67 Tutorial 2.2 Really Happy Hare
2.1 p. 67 Tutorial 2.2 Really Happy Hare aka hare jumps up, spins around, comes down, and says “that was fun”

21 2.1 Checkpoint p. 72 1. In an Alice world you have an object named hare. The hare object has a method named move. How would you write the method name using dot notation? 2. What causes a method to be executed automatically when a world is played. 3. What is a primitive method? 4. How do you see a list of the primitive methods that an object has? 5. When specifying a distance for the move method, what happens when you select other…. from the menu? When would you use this selection?

22 Checkpoint p. 72 continued
2.1 Checkpoint p. 72 continued 6. A fellow classmate has placed an instruction in the Method Editor. You ask her what the method does, and she says, “It calls another method.” What does she mean by that? 7. What is an argument? 8. What is a custom method? Do all classes provide custom methods? 9. How can you see a list of the custom methods that a class has?

23 Which one coaches the Mustangs and which one coaches the Eagles?
2.2 2.2 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. Which one coaches the Mustangs and which one coaches the Eagles?

24 namingConventions Most programming languages do NOT recognize spaces.
2.2 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 Note the space Note the space Which is easier to read? onehumpcamel or oneHumpCamel 24

25 Class Names method names begin with a lower case letter
2.2 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

26 Renaming Objects Methods
2.2 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.

27 Checkpoint p. 77 10. Why is it important that you give meaningful names to objects? 11. In most traditional programming languages, it is acceptable to have spaces in object or method names? 12. What is the camelCase naming convention? When is it used? 13. What is the PascalCase naming convention? When is it used?

28 2.3 2.3 Designing a Program Design the program Write the methods Test the methods Debug the methods Design requires planning…that follows the above steps Called Program Development Cycle Cycle is repeated until NO errors appear in the program.

29 Designing the Program Determine what the world is supposed to do.
2.3 Designing the Program Design the program Write the methods Test the methods Debug the methods Determine what the world is supposed to do. Read a problem statement that describes the which objects will appear in the world, and the actions that are to take place. What is the “Story”? 29

30 2.3 Designing the Program Design the program Write the methods Test the methods Debug the methods Break the problem statement down into series of steps Pseudocode or Flowchart 30

31 2.3 Writing the methods Design the program Write the methods Test the methods Debug 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 31

32 Testing Test to make sure it meets the following criteria:
2.3 Testing Design the program Write the methods Test the methods Debug the methods Test to make sure it meets the following criteria: Does it do what it was intended to do? Does it have any errors? Any undesired results? Is it efficient? Are there unnecessary steps? If the criteria are NOT met, then debugging occurs 32

33 2.3 Designing a Program Design the program Write the methods Test the methods Debug the methods 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 33

34 Tutorial 2-3 Using the program design cycle
2.3 Tutorial 2-3 Using the program design cycle Story: Recreate the opening scene of Lewis Carol’s Alice’s Adventures in Wonderland. Alice sees White Rabbit run by her, saying to itself, “Oh dear! Oh dear! I shall be late!”

35 2.3 Checkpoint p. 87 14. What are the steps in the program development cycle? 15. What are two tools that you can use to break down a problem into a series of steps? 16. What is a logical error? 17. When testing a method, what are three criteria that you should make sure the method meets?

36 2.4 Comments //comment tile 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. //comment tile

37 2.4 Tutorial 2-4 Inserting Comments

38 Checkpoint p. 90 18. Why are comments important?
2.4 Checkpoint p. 90 18. Why are comments important? 19. Do comments affect the way a program runs? 20. What symbols appear on the comment tile in Alice? Why were these symbols chosen?

39 2.5 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.

40 Tips for Setting Up the Initial Scene
2.5 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) 40

41 Tips for Setting Up the Initial Scene
2.5 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) 41

42 Tips for Setting Up the Initial Scene
2.5 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 42

43 2.6 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 placed within the Do together tile Make sure the duration for all items in a Do together are the same

44 The Do in order Structure
2.6 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

45 Tutorial 2-5 Creating simultaneously executed instructions
2.6 Tutorial 2-5 Creating simultaneously executed instructions Story: Two penguins (a brother and a sister) are facing each other, 2 meters apart. The brother penguin says, “Hey sis!”. Then the sister penguin says, “Hey brother!” Then the two penguins simultaneously move ½ meter toward each other and stop. Then they simultaneously jump in the air.

46 2.6 Checkpoint p. 104 21. How do you cause instructions to execute simultaneously? 22. How can you cause some of the instructions in a do together structure to be executed in order?

47 2.7 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 Author’s name

48 Review Questions p. 105 Short answer p. 107

49 Exercises 1. Scene from Alice’s Adventures in Wonderland
2. Animated Underwater World 3. Magic Cookies, Part 1 4. Magic Cookies, Part 2 5. Animal and Bicycle 6. Drag Racing 7. Playing Ball 8. Dancing 9. Apollo 15 Experiment 10. Tables, Chairs, and a Magic Broom 11. Movie Scene


Download ppt "Chapter 2: Programming in Alice"

Similar presentations


Ads by Google