51
PIIT Computer PIIT Computer Science Summer Science Summer Camp - Alice Camp - Alice July 10, 2012 July 10, 2012 Brenda Parker Brenda Parker Computer Science Department Computer Science Department MTSU MTSU

PIIT Computer Science Summer Camp - Alice July 10, 2012 Brenda Parker Computer Science Department MTSU

Embed Size (px)

Citation preview

PIIT Computer PIIT Computer Science Summer Science Summer

Camp - AliceCamp - Alice

PIIT Computer PIIT Computer Science Summer Science Summer

Camp - AliceCamp - AliceJuly 10, 2012July 10, 2012Brenda ParkerBrenda Parker

Computer Science DepartmentComputer Science DepartmentMTSUMTSU

April 18, 2023 Brenda Parker - Alice Workshop

2

Welcome – Day 2• Demonstrate Alice Worlds• Review Contest

April 18, 2023 Brenda Parker - Alice Workshop

3

Workshop Agenda• Discuss how programmers develop

programs (software)• Apply the “software life” cycle to

Alice• Create “custom” methods for Alice

Objects

April 18, 2023 Brenda Parker - Alice Workshop

4

Part I – Developing Software

Programmers use the “Software Development Cycle”

1. Design Phase2. Implementation Phase3. Testing Phase4. Debugging Phase

April 18, 2023 Brenda Parker - Alice Workshop

5

Developing SoftwareDesign 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 18, 2023 Brenda Parker - Alice Workshop

6

Developing SoftwareDesign 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 18, 2023 Brenda Parker - Alice Workshop

7

Developing SoftwareImplementation PhaseProgrammers will use a

programming language to enter instructions (coding)

In Alice, we add and position objects and code methods for the objects

April 18, 2023 Brenda Parker - Alice Workshop

8

Developing SoftwareTesting PhaseProgrammers 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

Developing SoftwareDebugging PhaseProgrammers will correct mistakes found

in the Testing PhaseIn Alice, correct the design of each

method and correct the initial state of the world

April 18, 2023 9Brenda Parker - Alice Workshop

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 taskIn Alice, this is performed by creating

“user defined methods” = “Custom World Methods”

Creating User MethodsWhy?1. Makes Alice programs easier to debug2. Makes Alice programs easier to create3. Supports “modular” designNow, let’s learn to create our own

methods!

April 18, 2023 11Brenda Parker - Alice Workshop

April 18, 2023 Brenda Parker - Alice Workshop

12

World Custom Methods• Created by the user• Used to break up large complex

methods into smaller more manageable methods

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

ExampleWe would break this task down into

3 separate tasks!1. Opening Scene2. Skating Scene3. Closing SceneTherefore, we need to create these

three methods!

Design Phase1. Determine objects needed

1. Ice skater2. 2 cones

2. Determine methods1. openingScene2. skatingScene3. closingScene

Design Phase3. Describr beginning scene

1. Snow world2. Class lake environment3. Add and position objects

1. Red and green cones2. 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

April 18, 2023 Brenda Parker - Alice Workshop

19

Custom World MethodHow to create and use Custom

World Methods1. Name the method2. Write the method3. Call the method (Tell Alice to

execute the method)

April 18, 2023 Brenda Parker - Alice Workshop

20

Create your Methods1. Name your method

1. Click on World in the Object Tree2. Click on create new method in the

World’s Details Panel3. Name the method – openingScene

Repeat above for the skatingScene and the closingScene methods

April 18, 2023 Brenda Parker - Alice Workshop

21

Custom World Method2. Write the method• Click on the world object in the

object tree• Click on methods• Click edit to write the method

Testing Phase1. Test each method to see if each

method works as desired2. Test to see if the methods work

with other methods.

Testing Phase –Part 1Test 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 2Test methods to see if they work with

other methods.1. Open world.my first method2. 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.

April 18, 2023 Brenda Parker - Alice Workshop

26

Testing Phase - Part 2

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 Questions1.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 18, 2023 28Brenda Parker - Alice Workshop

April 18, 2023 Brenda Parker - Alice Workshop

29

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 18, 2023 Brenda Parker - Alice Workshop

30

Alice DocumentationAdd “Comment Tiles” which• Name the program

(peguinsDance.a2w)• Programmer’s Name• Date• Program details

April 18, 2023 Brenda Parker - Alice Workshop

31

Adding Comments1. Drag a copy of the comment tile

from the bottom of the Editor Area and drop it into the method.

April 18, 2023 Brenda Parker - Alice Workshop

32

Adding Comments2. Click the phrase No comment and

type in your information.

ACTIVITYUse 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 penguins2) Create a story about space invaders3) Create a story about trip to the moon

April 18, 2023 Brenda Parker - Alice Workshop

34

Practice VIIIChoose 1 of the following. Be sure to add

comments:1. Page AL 120 - #1 Penguin Dance2. Page AL 123 - #2 Airport Animation3. Page AL 126 - #3 Ballerina Movements4. Create your own story (must have a

beginning, a middle and an end). Use primitive methods as well as your own methods.

Using Logic and Looping Structures

Logic• If –then– else• If something is true do this else do this!

April 18, 2023 35Brenda Parker - Alice Workshop

LOGICExample: 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 18, 2023 36Brenda Parker - Alice Workshop

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 18, 2023 37Brenda Parker - Alice Workshop

User Input ExampleSuppose 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 18, 2023 38Brenda Parker - Alice Workshop

User Input Example1 Create a world with the two objects.2. Drag the If/Else Control Structure to the

Editor Area.3.Set the If condition to true4.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 18, 2023 39Brenda Parker - Alice Workshop

User Input Example

April 18, 2023 40Brenda Parker - Alice Workshop

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 18, 2023 42Brenda Parker - Alice Workshop

April 18, 2023 Brenda Parker - Alice Workshop

43

Looping StructuresWhile• 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!

Looping StructuresLoop• Used to specify that a group of

statements is to be repeated a set number of times

April 18, 2023 44Brenda Parker - Alice Workshop

ExampleEdit 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 Variable1. Click on “create new variable”2. Indicate type of variable

1. Number2. Boolean3. Object4. Other

3. Give the variable a name4. 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. Edit the method to contain the variable2. Click create new variable called numberOfTimes3. Drag variable to beginning of method and set

value to expressions – numberOfTimes4. Drag World function “ask user for a number”

and place in set value to and add “How many times should the cuckoo sing?”

5. Drag loop and set expression to numberOfTimes6. Drag needed methods into the loop structure

Practice IXCreate an Alice project called

yourLastNameDay2.a2w which meets the following requirements.

1. Uses at least 3 user-defined methods2. Uses at least 1 variable3. Requires user input4. Tells an “interesting” story5. Uses if/else structure6. Contains a loop or while structure7. Contains proper documentation8. Print your program9. Submit your program to the Day 2 folder

April 18, 2023 51Brenda Parker - Alice Workshop