Workshopday2 - CS Community – Computer Science

advertisement
PIIT Computer Science
Summer Camp - Alice
July 10, 2012
Brenda Parker
Computer Science Department
MTSU
Welcome – Day 2
• Demonstrate Alice Worlds
• Review Contest
April 13, 2015
Brenda Parker - Alice Workshop
2
Workshop Agenda
• Discuss how programmers develop
programs (software)
• Apply the “software life” cycle to
Alice
• Create “custom” methods for Alice
Objects
April 13, 2015
Brenda Parker - Alice Workshop
3
Part I – Developing
Software
Programmers use the “Software
Development Cycle”
1. Design Phase
2. Implementation Phase
3. Testing Phase
4. Debugging Phase
April 13, 2015
Brenda Parker - Alice Workshop
4
Developing Software
Design Phase
•
•
•
Programmers will learn about all
specifications (what the program should do)
Programmers will create a list of instructions
needed to solve the problem
Programmers will break complex methods
down into a smaller methods called “modules”
April 13, 2015
Brenda Parker - Alice Workshop
5
Developing Software
Design Phase
In Alice, we should learn :
1. Which objects are needed?
2. Which methods are needed?
3. What does the first scene look
like?
April 13, 2015
Brenda Parker - Alice Workshop
6
Developing Software
Implementation Phase
Programmers will use a programming
language to enter instructions
(coding)
In Alice, we add and position objects
and code methods for the objects
April 13, 2015
Brenda Parker - Alice Workshop
7
Developing Software
Testing Phase
Programmers will “test” the program to see
if it works properly and meets its
specifications.
Testing involves testing each method to see
if it works by itself and with other
methods
April 13, 2015
Brenda Parker - Alice Workshop
8
Developing Software
Debugging Phase
Programmers will correct mistakes found in
the Testing Phase
In Alice, correct the design of each method
and correct the initial state of the world
April 13, 2015
Brenda Parker - Alice Workshop
9
Good Programmers know
the importance of DESIGN
1. Design their software carefully!
2.Use a “Modular” design
• break a large task down into smaller tasks
called modules
• Each module performs one task
In Alice, this is performed by creating “user
defined methods” = “Custom World
Methods”
Creating User Methods
Why?
1. Makes Alice programs easier to debug
2. Makes Alice programs easier to create
3. Supports “modular” design
Now, let’s learn to create our own methods!
April 13, 2015
Brenda Parker - Alice Workshop
11
World Custom Methods
• Created by the user
• Used to break up large complex
methods into smaller more
manageable methods
April 13, 2015
Brenda Parker - Alice Workshop
12
Example
Suppose we wish to create an “Ice
Skater World” which opens with an
introduction by the skater. Then,
the skater skates around 2 cones and
jumps in the air. At the end the
skater says goodbye and the camera
circles the skater.
Example
We would break this task down into 3
separate tasks!
1. Opening Scene
2. Skating Scene
3. Closing Scene
Therefore, we need to create these
three methods!
Design Phase
1. Determine objects needed
1. Ice skater
2. 2 cones
2. Determine methods
1. openingScene
2. skatingScene
3. closingScene
Design Phase
3. Describr beginning scene
1. Snow world
2. Class lake environment
3. Add and position objects
1. Red and green cones
2. Skater in the middle of the cones
Implementation Phase
• Open Alice
• Choose snow world
• add Class Lake
Environment
• Add ice skater and
two cones (red and
green) as shown
• Save your world as
iceSkate1.a2w
Implementation Phase
(coding)
• Write code for your three methods
– openingScene
– skatingScene
– closingScene
Custom World Method
How to create and use Custom World
Methods
1. Name the method
2. Write the method
3. Call the method (Tell Alice to
execute the method)
April 13, 2015
Brenda Parker - Alice Workshop
19
Create your Methods
1. Name your method
1. Click on World in the Object Tree
2. Click on create new method in the
World’s Details Panel
3. Name the method – openingScene
Repeat above for the skatingScene and
the closingScene methods
April 13, 2015
Brenda Parker - Alice Workshop
20
Custom World Method
2. Write the method
• Click on the world object in the
object tree
• Click on methods
• Click edit to write the method
April 13, 2015
Brenda Parker - Alice Workshop
21
Testing Phase
1. Test each method to see if each
method works as desired
2. Test to see if the methods work
with other methods.
Testing Phase –Part 1
Test each method to see if it works.
1. Test the openingScene method
2. Play the video to see if it works.
3. If it doesn’t work properly, edit the
method and replay.
Testing Phase – Part 1
• Test all methods to see if they work
properly.
Testing Phase – Part 2
Test methods to see if they work with other
methods.
1. Open world.my first method
2. Click and drag your method names to the
editor window as shown.
3. Make sure that world.my first method
begins when the world starts.
Testing Phase - Part 2
April 13, 2015
Brenda Parker - Alice Workshop
26
Debugging Phase
• Developers should attempt to
correct mistakes that have been
found.
• During the debugging phase,
developers may often find
improvements that can be made.
Practice VII Questions
1.What is the difference between “primitive”
methods and custom methods?
2. Give two reasons that custom methods are often
used in Alice.
3. What is the name of the method that is executed
when your animation first begins?
4. What are the three steps for creating custom
world methods?
5.What does “call” the method mean?
6. How are custom methods “called”?
7. Name the 4 steps of the Software Development
Cycle.
April 13, 2015
Brenda Parker - Alice Workshop
28
Software Documentation
• Written text and visual material (chart)
that describe computer software
• Good software requires good
documentation.
– Comments that appear in the program
– Notes that appear while the program is running
– Instruction manual supplied with the software
April 13, 2015
Brenda Parker - Alice Workshop
29
Alice Documentation
Add “Comment Tiles” which
• Name the program
(peguinsDance.a2w)
• Programmer’s Name
• Date
• Program details
April 13, 2015
Brenda Parker - Alice Workshop
30
Adding Comments
1. Drag a copy of the comment tile
from the bottom of the Editor Area
and drop it into the method.
April 13, 2015
Brenda Parker - Alice Workshop
31
Adding Comments
2. Click the phrase No comment and
type in your information.
April 13, 2015
Brenda Parker - Alice Workshop
32
ACTIVITY
Use the “software development cycle” and
develop your own video. To receive points
for this exercise, you should design your
animation using the DAY 2 Assignment
Sheet. Some ideas:
1) Create a story about dancing penguins
2) Create a story about space invaders
3) Create a story about trip to the moon
Practice VIII
Choose 1 of the following. Be sure to add
comments:
1. Page AL 120 - #1 Penguin Dance
2. Page AL 123 - #2 Airport Animation
3. Page AL 126 - #3 Ballerina Movements
4. Create your own story (must have a
beginning, a middle and an end). Use
primitive methods as well as your own
methods.
April 13, 2015
Brenda Parker - Alice Workshop
34
Using Logic and Looping
Structures
Logic
• If –then– else
• If something is true
do this
else
do this!
April 13, 2015
Brenda Parker - Alice Workshop
35
LOGIC
Example: Suppose we have two
objects, Elvis and a cuckoo clock.
Let’s ask the user if the user wants
the Elvis to sing or does the user
wish to see the cuckoo clock sound
out 3 times!
April 13, 2015
Brenda Parker - Alice Workshop
36
How do we allow the user
to input a value?
Asking the user for input while a
program is running is called
“interactive input”.
How do we do this in Alice?
April 13, 2015
Brenda Parker - Alice Workshop
37
User Input Example
Suppose that we have a world with
Elvis and a cuckoo clock.
The program should ask, “Do you want
Elvis to sing?
If the user answers, “YES”, Elvis will
sing. Otherwise, the cuckoo bird will
sound out cuckoo 3 times.
April 13, 2015
Brenda Parker - Alice Workshop
38
User Input Example
1 Create a world with the two objects.
2. Drag the If/Else Control Structure to the
Editor Area.
3.Set the If condition to true
4.Select the world function called “ask user
for yes or no”
5.Use the function in the “if else” structure.
6. Click Question=Yes or No? to add the
question.
April 13, 2015
Brenda Parker - Alice Workshop
39
User Input Example
April 13, 2015
Brenda Parker - Alice Workshop
40
Better Example – User
Defined Methods
Using Logic and Looping
Structures
Loop – statements that are executed
repeatedly.
Types of Loops
• While
• Loop
• For all in order
• For all together
April 13, 2015
Brenda Parker - Alice Workshop
42
Looping Structures
While
• Continue to repeat until a certain
condition occurs.
• Example: Suppose that we have a
penguin that we wish to continue to
move toward a hole in the ice until he
“almost” reaches the hole!
April 13, 2015
Brenda Parker - Alice Workshop
43
Looping Structures
Loop
• Used to specify that a group of
statements is to be repeated a set
number of times
April 13, 2015
Brenda Parker - Alice Workshop
44
Example
Edit the elvisSing method so that the user is asked
to input the number of times Elvis should sing.
1. Drag the loop structure to the beginning of the
method and set to 1 time.
2. Drag the world function “ask the user for a
number” and place in the 1 time slot
3. Choose other to ask appropriate question.
4. Drag methods to the loop structure
Loop Example
variables
• Variable – a name that refers to a piece of
the program’s memory, in which a value can
be stored, retrieved, and changed.
• In Alice, there are two kinds of variables
– World variable – variables that can be used by
all methods
– Method variable – variable that can only be
used in a method that creates it.
Method Variable
1. Click on “create new variable”
2. Indicate type of variable
1.
2.
3.
4.
Number
Boolean
Object
Other
3. Give the variable a name
4. Click on OK
Example
• Use the Elvis and cuckoo clock world
and update the program so that you
ask the user how many times the
Elvis/cuckoo should sing. Use a
variable called numberOfTimes
(camelCase)
Using Variable in a Loop
1.
2.
3.
4.
5.
6.
Edit the method to contain the variable
Click create new variable called numberOfTimes
Drag variable to beginning of method and set
value to expressions – numberOfTimes
Drag World function “ask user for a number”
and place in set value to and add “How many
times should the cuckoo sing?”
Drag loop and set expression to numberOfTimes
Drag needed methods into the loop structure
Practice IX
Create an Alice project called
yourLastNameDay2.a2w which meets the
following requirements.
1. Uses at least 3 user-defined methods
2. Uses at least 1 variable
3. Requires user input
4. Tells an “interesting” story
5. Uses if/else structure
6. Contains a loop or while structure
7. Contains proper documentation
8. Print your program
9. Submit your program to the Day 2 folder
April 13, 2015
Brenda Parker - Alice Workshop
51
Download