Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects...

20
Today’s Agenda 1. Collect Pre-Lab 4 2. Alice Programming Assignment Storyboards 3. Classes 4. Objects 5. Methods 6. Assign pair programming teams and meet upstairs for Lab 4

Transcript of Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects...

Page 1: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.

Today’s Agenda

1. Collect Pre-Lab 4

2. Alice Programming Assignment Storyboards

3. Classes

4. Objects

5. Methods

6. Assign pair programming teams and meet upstairs for Lab 4

Page 2: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.

Explore the PossibilitiesCS 112: Foundations of Computer Science

Classes, Objects, and Methods

Page 3: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.

Classes, Objects, & Methods

• Object-oriented programming uses classes, objects, and methods as basic programming components

• These components help to organize a large program into small modules

Page 4: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.

In our programs,we have been using…

• Classes

• Objects

An object is an instance of a class. Class: Frog Objects: frog, frog1, frog2, frog3

Page 5: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.
Page 6: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.

Snowman Movie

Do in order

Catch Attention – snowman tries to catch the attention of the snowwoman

Blink eyes – snowwoman turns to look and the snowman blinks his eyes

Reactions – snowwoman blushes and turns away and the snowman

is disappointed

Movie Treatmentin 3 scenes

Page 7: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.

Next Step

• The next step is to break down each scene into simpler steps– Example:

Scene 1: Catch Attention

Do in order

snowman turns to face snowwoman

snowman's head turns to face camera

snowman says "Ahem"

snowman's head turns to face snowwoman

Page 8: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.

Demo: Starting a new world-level

method

• select the World tile in the Object Tree

•select the methods tab in the details area

•click on the "create new method" button

Page 9: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.

World-level methods

• scene1 is a world-level method because it is defined as a method for the World and has instructions that involve more than one object (snowman, snowwoman, camera)

Page 10: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.

Parameters

Movie treatment: beetle band tunes up

Page 11: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.

Stepwise Refinement

Four scenes: each band member tunes upDo together Do in order georgeBeetle move up georgeBeetle move down play sound

Do together Do in order ringoBeetle move up ringoBeetle move down play sound

Do together Do in order paulBeetle move up paulBeetle move down play sound

Do together Do in order lennonBeetle move up lennonBeetle move down play sound

Page 12: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.

Parameters

tuneUp

Parameters: bandMember, music

Do together Do in order bandMember move up bandMember move down play music

Page 13: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.

Kinds of Parameters

• Alice provides several kinds of parameters that can be used in your own methods.

Page 14: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.

A Number parameterWe could add a Number parameter to specify the height the bandMember jumps up and down.

Note that the call to the method must now include an argument for the height.

Page 15: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.

Class-level Methods

• Some actions are naturally associated with a specific class of objects– A person walking– A wheel rolling– An iceSkater skating

• We can write our own methods to define an action for a specific class of objects -- a class-level method

Page 16: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.

Textbook Example Create a skate method for ice skater objects?

We need to:

(1) tell Alice to associate the new method (the one we are about to write) with an ice skater, and

(2) write a new method to animate the ice skater skating.

Page 17: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.

First, to associate the animation with the ice skater

• select the iceSkater tile in the Object Tree

•select the methods tab in the details panel

•click on the create new method button

Page 18: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.

• The slide actions each require several motion instructions, so we will break down these two actions into smaller steps

SkateDo together move skater forward 2 meters Do in order slide on right leg slide on left leg

Page 19: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.

Creating a new class1) Rename iceSkater as cleverSkater.

2) Save out as a new class. Alice saves the new class as CleverSkater.a2c

Page 20: Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.

Importing CleverSkater• An instance of the CleverSkater class can

be added to a new world – use File|Import.