Variables and Functions Chapter 3 3-1. Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.

Slides:



Advertisements
Similar presentations
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 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.
 Variables  What are they?  Declaring and initializing variables  Common uses for variables  Variables you get “for free” in Processing ▪ Aka: Built-in.
Class-level Methods Chapter 6. Class-level Method Is specific to a class of objects We can give a class new abilities/methods Only involves this one class.
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. Interactive Real world is interactive User determines order of actions instead of programmer.
Repetition Structures
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Functions and Visual Effects Chapter 6 Part 3. Built-in Functions We have been using built-in functions so far 2.
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.
Programming in Alice Chapter 2. Today’s Agenda Designing a Program Writing Methods Executing Instructions Simultaneously Comments Tips for Setting Up.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Alice Variables Pepper. Set to Java look Edit / preferences restart.
Creating Functions Pepper. Homework Asking the user: –Drag variable to create a set statement –Drag a world function NumberDialog or StringDialog over.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley This week: Whew!!! The last homework was tough! The homework for this week.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Branching and Looping Examples, cont’d. Remember the generic triple jump world…
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Class-level Methods Chapter 6 part 1. Classes and Objects Classes o In Alice, classes are predefined as 3D models Objects o An object is an instance of.
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Exam scores by range 3-1.
Four Fundamental Pieces Instruction Control Structure Function Expression.
Variables & Random Number Generation.  A penguin is playing arctic basketball. The penguin has a basketball and will push the basketball toward.
Introduction to Programming with RAPTOR
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.
What we will do today Learn about functions in Alice.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Programming: Putting Together the Pieces Built-in Questions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
ITEC 109 Lecture 7 Operations. Review Variables / Methods Functions Assignments –Purpose? –What provides the data? –What stores the data? –What type of.
Variables and Functions Alice. Naming is Important If you get a new pet one of the first things you do is name it Gives you a way to refer to the new.
Functions Sec 8-11 Web Design. Objectives The Student will: Understand what a function is Know the difference between a method and a function Be able.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
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.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
CompSci 4 Chap 6 Sec 2 Sep 30, 2010 Prof. Susan Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not a Flutterbudget.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-1 Lecture Objectives To understand: –what values can be stored in a Boolean.
An Introduction to Programming Using Alice 2.2, Second Edition Chapter 7 Recursive Algorithms.
1 Quiz Show Programming Terms. 2 Alice - 3D Virtual Programming Vocabulary Quiz Board Chapter 1 Chapter 2a Chapter 2b Chapter 3 Chapter 4 $100 $200 $300.
Programming: Putting Together the Pieces Built-in Functions and Expressions Sec 8-5 Web Design.
Obj: to recognize built-in functions and expressions HW: Read Section 3.1 and do HW4 Edmodo article due Sunday at 8pm Edmodo feedback due 8pm 10/17 Do.
Programming: Putting Together the Pieces Built-in Functions and Expressions Sec 8-5 Web Design.
Starting Out with Alice: A Visual Introduction to Programming
Chapter 3: Variables, Functions, Math, and Strings
Chapter 3: Variables, Functions, Math, and Strings
Data Types
Alice Variables Pepper.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Building Java Programs
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Using Lists and Functions to Create Dialogue
ICT Gaming Lesson 3.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Data Types and Maths Programming Guides.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Presentation transcript:

Variables and Functions Chapter 3 3-1

Variables Named storage location in computer’s memory Programs may need to store data when running Types of data that can be stored o Local variables o Parameter variables o Class-level variables o World-level variables 3-2

Variable Types Local variables o Belongs to a specific method o Only used in that method o Variables cease to exist when method stops o Will be talked about today Parameter variables o Holds argument that is passed to a called method Class-level variables o It is like a property and belongs to a specific object World-level variables o It is a world-level property 3-3

Creating Local Variables Local variables belong to a specific method (such as world.my first method) Create variable by clicking on create new variable in desired method Variables require 3 things o Name o Type o Initial value 3-4 name type value

Variable Definition  Variable Names o Must be unique within the method or object o Should be meaningful and reflect the variable’s purpose o Named using camelCase  Variable Types o Numbers, Boolean, Objects, Other (such as String, Color, Sound, etc.)  Initial Value o Value initially stored in the variable 3-5

Variables Tile appearance shows the type of variable Numbers Boolean Objects String Variable declaration - creating a variable 3-6 variable area

Variable Assignment  Variables have an initial value  Initial value held until a different value is assigned  New values can be assigned while the method is running o Use Set instructions o Done by dragging variable tile into Methods Editor 3-7

Review What is a variable? What are three things that must be specified when creating a new variable? Where in the Method Editor do variable tiles appear? What do the characters 123 appearing on a variable tile tell you? What do characters abc on a variable tile tell you? How do you create a set instruction for a variable? 3-8

Function Asks a question to o Check a condition o Compute a value Used to get information about… o Size of objects  What is snowwoman's height? o Relationship of one object to another  What is distance between lunar robot and rock? Used to get other information o Time o Ask user for information

Value What a function returns after it o Asks question o Or performs a computation Type of value depends on kind of function o distance to returns a number o is to the left of returns a Boolean value Number value o Whole number ex: 3 meters o Fractional value, ex: 1.2 meters o In lunar example  What is distance of robot to rock?

Function vs. Method Functions o Perform calculations o Determine state of an object or system o Return a value Methods perform an action 3-11

Types of Values Number o 3, or 1.3 Boolean o true, false String o “Slithy Toves?” Object o lunarRobot, alien Position in world o (0, 0, 0) – (x,y,z) center of an Alice world

World Level Primitive Functions  List of world level functions categories o Boolean logic o Math o Random o String o Ask user o Mouse o Time o Advanced math o Other 3-13

Asking User for Input  World has three primitive functions that ask for user input  Each question is shown in a dialog box  Ask user for a number  User enters a number  Ask user for yes or no  User clicks on yes or no  Ask user for a string  User answers with words or a sentence 3-14

Adding Question for Number

Place Answer in Variable 3-16

Class Primitive Object Functions  Objects have different primitive functions from the world level  Class level functions o Proximity o Size o Spatial relation o Point of view o Other Object primitive proximity functions

Using Function distance to Built-in distance to function o Determines distance from center of one object to center of another object o Better than guessing distance to object An Alice function is not a "stand-alone" instruction o It is nested within another instruction

Review What makes a function different from a method? How do you see a list of functions an object has? What are the three primitive world functions that ask the user to input a value? What are some class level functions? What does the primitive distance to function do? 3-19

Homework Read chapter 3 Do tutorials o Tutorial 3-1 Creating and using a variable, p 116 o Tutorial 3-2, Creating a set instruction, p. 118 o Tutorial 3-3, Calling an ask user function, p. 122 o Tutorial 3-4, Using a proximity function, p. 127 Do lab assignments Due one week after its assigned