Branching and Looping Examples, cont’d. Remember the generic triple jump world…

Slides:



Advertisements
Similar presentations
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Advertisements

Strings Strings are sequences of characters and / or digits “Alice” “ ” “I would like 3 peaches” When a model says or thinks, it is using a.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010 modified July 2011.
PIIT Computer Science Summer Camp - Alice July 10, 2012 Brenda Parker Computer Science Department MTSU.
How Tall Are You? Introducing Functions By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008 Updates made June 2014 by.
Decision Structures Chapter 4. Chapter 4 Objectives To understand: o What values can be stored in a Boolean variable o What sequence structures are and.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Events Chapter 7. Interactivity The real world is interactive User determines order of actions instead of programmer.
Events Chapter 7. Interactive Real world is interactive User determines order of actions instead of programmer.
Don Slater Wanda Dann
Repetition Structures
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Fall 2009ACS-1805 Ron McFadyen1 Functions A function is a collection of statement, similar to a method, but a function is defined to return a value to.
Alice Variables Pepper. Set to Java look Edit / preferences restart.
Exploring Events. Try this Start Alice and create a blank world using the grass template. Add an instance of a BlueBallerina. Add an instance of a PinkBallerina.
Calvin and Hobbes Teach Properties and Functions Created by Daniel MacDonald under the direction of Professor Susan Rodger Duke University June 2013.
METHODS!.  A method is a sequence of instructions or behaviors that will be carried out when requested.  You can use them to create new methods so that.
As you come in…  DOWNLOADS FOR TODAY:  CarGameTeacherStarter.a2w  Online student textbook.
Line up By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
V Avon High School Tech Club Agenda Old Business –Delete Files New Business –Week 16 Topics: Intro to HTML/CSS –Questions? Tech Club Forums.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Making a Timer in Alice.
Programming With Alice. Alice Free Java based, 3D programming tool Enables the manipulation and interaction of 3D objects Can also.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
THE BIG PICTURE. How does JavaScript interact with the browser?
Decision Structures Chapter 4 Part 2. Chapter 4 Objectives To understand o What relational operators are and how they are used o Boolean logic o Testing.
Events Chapter 7 Part 2. While a Key is Pressed Event Specialized event An event occurs when you press a key and continues until you take your finger.
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
Teaching a character to walk in more than one world: Parameters and Inheritance. By Lana Dyck under the direction of Professor Susan Rodger Duke University.
By Melissa Dalis Professor Susan Rodger Duke University June 2011 Multiplication Table.
© Jalal Kawash Programming Peeking into Computer Science 1.
A Simple Quiz: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009, added Part 2 July 2011.
Making a Timer in Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University July
Piñata Game: Keeping Score in Alice By Maggie Bashford Professor Susan Rodger Duke University July
Flow Control: boolean expressions, “if” selection statements (Alice In Action, Ch 4) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September.
1 ball, 2 ball, red ball, blue ball By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Mathematical Expressions, Conditional Statements, Control Structures
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
Can I get your number? By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.
Balancing the scales: Inequalities By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
5 Event Handling Interactive Programming Suggested Reading Interaction: Events and Event Handling, Supplemental Text for CPSC 203 Distributed this term.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-1 Lecture Objectives To understand: –what values can be stored in a Boolean.
How Tall Are You? Introducing Functions for Alice 3 By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008 Updates made.
An Introduction to Programming Using Alice 2.2, Second Edition Chapter 7 Recursive Algorithms.
Making Billboards By Deborah Nelson Duke University, Under the direction of Professor Susan Rodger, July 14, 2008.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
A Simple Quiz for Alice 3.2:
Chapter 3: Variables, Functions, Math, and Strings
Chapter 3: Variables, Functions, Math, and Strings
Simple Control Structures
Repetition Control Structures
Let's Race! Typing on the Home Row
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Michelle Venable-Foster Barb Ericson Jan 2007
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
A Simple Quiz for Alice 3.2:
Using Functions
An Introduction to Programming Using Alice 2.2, Second Edition
Computer Science Core Concepts
How Tall Are You? Introducing Functions
Programming with Alice
Relational Expressions
under the direction of Professor Susan Rodger
Presentation transcript:

Branching and Looping Examples, cont’d

Remember the generic triple jump world…

Let’s change this to be interactive.

User input functions in Alice ask user for a number ask user for yes or no ask user for a string

Start Alice and open genericTripleJump Look at world. my first method Note that the statements there form a linear sequence. We want to modify this algorithm.

The first step is to add an If/Else instruction to the method. Drag a copy of the If/Else tile from the bottom of the editor area. Drop it into the method just below the three jump instructions.

Adding If/Else instructions When adding an If/Else, you will be prompted to choose between true “and” “false” as an initial value for the condition. This value is merely a placeholder. We will always replace this value with a Boolean expression of a condition we want to test.

Replace the placeholder condition in the If/Else instruction with a function. We need the function that will allow us to ask the user a yes/no question.

We want Alice to jump only if the user answers yes to our query. Need to move the instruction that causes Alice to jump to the If clause of our If/Else instruction.

genericTripleJumpWhile.a2w genericTripleJumpLoop.a2w

A Sentinel Sailing Loop Sailboat will turn to face the object Will sail one meter forward This process continues until the sailboat is within 5 meters of the object While (NOT (the sailboat is within 5 meters of the [object])) { turn to face [object] move forward 1 meter }

A Sentinel Sailing Loop Let’s create a sail to method that will work with any object. It should accept the target object as an input parameter. This will be similar to the way the primitive move method accepts direction and amount

A Sentinel Sailing Loop Sailboat will turn to face the object Will sail one meter forward This process continues until the sailboat is within 5 meters of the object While (NOT (the sailboat is within 5 meters of the [object])) { turn to face [object] move forward 1 meter }

A Sentinel Sailing Loop Sailboat will turn to face the object Will sail one meter forward This process continues until the sailboat is within 5 meters of the object While (NOT (the sailboat is within 5 meters of the [object])) { turn to face [object] move forward 1 meter }

A Sentinel Sailing Loop Sailboat will turn to face the object Will sail one meter forward This process continues until the sailboat is within 5 meters of the object While (NOT (the sailboat is within 5 meters of the [object])) { turn to face [object] move forward 1 meter }

Let’s generalize sailTo so that we can sail to any object.