Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

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 for Lab 4

2 Explore the Possibilities CS 112: Foundations of Computer Science Classes, Objects, and Methods

3 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

4 In our programs, we have been using… Classes Objects An object is an instance of a class. Class : Frog Objects : frog, frog1, frog2, frog3

5

6 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 Treatment in 3 scenes

7 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

8 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

9 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 )

10 Parameters Movie treatment: beetle band tunes up

11 Stepwise Refinement Four scenes: e ach band member tunes up Do 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

12 Parameters tuneUp Parameters: bandMember, music Do together Do in order bandMember move up bandMember move down play music

13 Kinds of Parameters Alice provides several kinds of parameters that can be used in your own methods.

14 A Number parameter We 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.

15 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

16 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.

17 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

18 The slide actions each require several motion instructions, so we will break down these two actions into smaller steps Skate Do together move skater forward 2 meters Do in order slide on right leg slide on left leg

19 Creating a new class 1) Rename iceSkater as cleverSkater. 2) Save out as a new class. Alice saves the new class as CleverSkater.a2c

20 Importing CleverSkater An instance of the CleverSkater class can be added to a new world – use File|Import.


Download ppt "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."

Similar presentations


Ads by Google