Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects...
-
Upload
edward-kristian-hudson -
Category
Documents
-
view
212 -
download
0
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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/1.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/2.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/3.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/4.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/5.jpg)
![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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/6.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/7.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/8.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/9.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/10.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/11.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/12.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/13.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/14.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/15.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/16.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/17.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/18.jpg)
• 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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/19.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022070407/56649e205503460f94b0c6bd/html5/thumbnails/20.jpg)
Importing CleverSkater• An instance of the CleverSkater class can
be added to a new world – use File|Import.