exam wednesday no inclass assignment this week. friday labs will help with individual homework...

36
Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam Tuesday 1:30-3 in Main 416 Tuesday 7-8, in SER 005 Posted Study Guide No make-ups given without prior approval 2-1

Upload: amice-shepherd

Post on 16-Dec-2015

223 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

Exam Wednesday

No inclass assignment this week.

Friday labs will help with individual homework assignment due Friday midnight

Review for exam– Tuesday 1:30-3 in Main 416

– Tuesday 7-8, in SER 005

– Posted Study Guide

No make-ups given without prior approval

2-1

Page 2: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

Review of chapter 9

Center of an object is not computed – it depends on what is most useful for the object.

When you move an object to the world (0,0,0) - it will often be half beneath the ground

Where should the “center” of the following be:– bat

– person

– fish

– ball

The answers depend on what the object designer thought you would want to do with it.

2-2

Page 3: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

Starting Out with Alice: A Visual Introduction to Programming

First Edition

by Tony Gaddis

Chapter 10:Programming in Alice

Page 4: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

3D text – can be created like any object

2-4

Page 5: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

You can also add a jpg, gif, or tif file…

Go to file> Make Billboard

Then select the file you want to include

RightClick>Copy is invaluable!

Be sure to use undo! That can save lots of frustration

2-5

Page 6: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-6

Chapter 10 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

Page 7: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

Tips

You will learn Alice best by exploring – like you would with a new cell phone. You take it out of the box – poke and prod.

You have a general idea of what you would like to do.This directs your exploration (how can I make creation of similar instructions easier?)

As you discover interesting things, email them to me and I’ll post them!

ALICE is the vehicle to explore algorithms, programming concepts, and logical thinking.

Proficiency in ALICE is NOT THE GOAL.

2-7

Page 8: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-8

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

Page 9: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-9

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”– later on we’ll have coach.yell or frog.jump

dot notation “qualifies” the command – who yells

the period

is called a

“dot”

2.1

Page 10: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

Method names should be meaningful

2-10

Rightclick to rename

Page 11: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-11

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

2.1

Page 12: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-12

world.my first methodMethods play the instructions (tiles) that are dragged into the Method Editor

This method of creating instructions is a bit tedious, but is done to reduce errors

2.1

Page 13: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-13

Primitive Methods – ALL objects can doAll objects have a common set of built-in method for performing actions.All objects can move, turn, change size, and more.

Example:Hare has primitive methods to move, turn, roll, resize, say

dot notation: hare.move

2.1

Page 14: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-14

TerminologyCalling the method. hare.move (like subject/verb)– executing or performing the instructions of 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

object

method

argument argument

2.1

Page 15: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-15

Editing Tag

Holds possible additional arguments

What appears depends on the method called– duration

specifies amount of time for action to take placedefault (1 second)

2.1

Page 16: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-16

Deleting – be sure to click on instruction itself not the object

Right-click the instruction and select delete

OR drag the instruction tile to the trash can

2.1

Page 17: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-17

CopyingRight-click the instruction and select copy

Drag the instruction tile to the clipboard– when the clipboard turns

green, drop the tile

– Later, click on the clipboard and drag it back to the Method Editor

– The clipboard only contains one thing at a time. You can request multiple clipboards. (Edit>Preferences>SeldomUsed)

2.1

Page 18: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-18

Custom Methods

In addition to primitive methods (the things that ALL objects can do)…some objects have custom methodsWhen objects is selectedfrom gallery, a listing ofcustom methods appearsNames of the custommethods give clues as towhat the method does

What do you think the foottap

custom method does?

2.1

Page 19: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-19

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?

Page 20: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-20

namingConventions

Most programming languages do NOT recognize spaces– Alice allows spaces

method.my first method

When spaces are not allowed, how do you combine more than one word in naming?– Capitalize subsequent words

– Called camelCase

2.2

Note

the

space

Note

the

space

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Which is easier to read?

onehumpcamel

or

oneHumpCamel

Page 21: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-21

Class Names

method names begin with a lower case letter

Class names are capitalized

This simple capitalization rule is very helpful.

No spaces, so each word is capitalized

– This convention is called PascalCase

2.2

Page 22: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-22

Renaming

Objects– Right-click object’s tile in

the object tree and selectrename.

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

Page 23: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

Let’s try the following

Playing ball

Two players kick ball back and forth

What happens together?

What if we want to add a frog on top of the ball?

What if we want the ball to spin?

What if we want the ball to bounce?

2-23

Page 24: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

Orientation

If you want two objects to move together, there are two choices:– they can have the same orientation (same coordinate system

orientation) – orient to

– one can be a vehicle for the other. (Under properties for “riding” object)

2-24

Page 25: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

As seen by

You know each object has it’s own sense of direction, but suppose we want the ball (which may be twisted) to bounce upwards with respect to the ground.

Select “move up” but use “more” to request “asSeenBy = ground”

2-25

Page 26: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

Move to

Alice can move objects to a particular location, but it is more likely it moves to another location in the scene.

Try using moveTo to go to the camera

MoveToward allows you to move in the direction of an object without aligning center points.

2-26

Page 27: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-27

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 program Write the methods Test the methods Debug the methods

Page 28: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

Why design?

It is common for students just to start!

Why should they take the time to jot down a plan?– Solve the right problem

– Allow for reuse – plan to use the same code. On magnets, for example, - do all the objects get to the magnet the same way? Will the instructions work from any location? Which is better for reuse?

2-28

Page 29: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

Decomposition

The machine only understands about 100 operations. What makes it difficult if the ways they are put together.

Chess – only six types of chess pieces which move in simple patterns. The complexity comes with the combinations

In programming we need a way of managing the pieces.

used interchangeably: decomposition, stepwise refinement, top-down design

2-29

Page 30: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-30

CommentsA comment is a note explaining the code

Crucial part of the code

Makes the code understandable

Alice ignores comments when it runs your program

2.4

//comment tile

Page 31: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-31

Tips for Setting Up the Initial SceneMethods can also be called to help in initial positioning

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

Page 32: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

10-32

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

Page 33: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-33

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

Page 34: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-34

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

Page 35: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-35

Executing Instructions Simultaneously

By default, instructions are executed one after the other…in the order they appear in the Methods Editor

For simultaneous actions, dragDo together into the MethodsEditor

Other instructions can be placewithin the Do together tile

Make sure the duration for allitems in a Do together are the same

2.6

Page 36: Exam Wednesday No inclass assignment this week. Friday labs will help with individual homework assignment due Friday midnight Review for exam –Tuesday

2-36

The Do in order StructureBy 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