Variables and Functions Chapter 3

Similar documents
World-level Classes and Methods. Chapter 6

Decision Structures. Chapter 4

Class-level Methods. Chapter 6 part 1

Getting Started with Java Using Alice. 1 Copyright 2013, Oracle and/or its affiliates. All rights reserved.

IT Introduction to Programming for I.T. Midterm Exam #1 - Prof. Reed Spring 2008

Plotting Points. By Francine Wolfe Professor Susan Rodger Duke University June 2010

This tutorial will teach you about operators. Operators are symbols that are used to represent an actions used in programming.

Choose the best answer from each of the following; answer A for True, B for False for any T/F questions.

Alice: A Free 3D Animation World for Teaching Programming

Peeking into Computer Science Alice Lab Manual. Lab Manual. Programming

Events (Alice In Action, Ch 6)

Classes, Objects, and World-level Methods. Alice

Events (Alice In Ac.on, Ch 6)

Midterms Save the Dates!

Class #1. introduction, functions, variables, conditionals

Gaddis: Starting Out with Alice Test Bank Chapter Two 1 Chapter Two

Duration 30 minutes Notes This tutorial was built using Alice

Using Formulas and Functions in Microsoft Excel

Data types Expressions Variables Assignment. COMP1400 Week 2

Appendix A Reference: Built-in Methods

Kids College Computer Game Programming Exploring Alice 3.X and Object-Oriented Programming

Creating and Triggering Animations

Using Functions in Alice

The Alice Scene Editor

Click the buttons in the interactive below to become familiar with the drawing tool's commands.

Introduction to Electronics Workbench

Methods & Classes in Alice

Alice. Coverage. Mathematical Expressions, Conditional Statements, Control Structures. Arithmetic Expressions Built-in Functions Conditional Execution

Introduction to Excel 2013

Name Introduction to Computer Science. 1. A sequence of instructions that tell the computer what to do is known as a?

SELECTION. (Chapter 2)

Making Objects Move in Unison: Using Lists. Overview

Making Objects Move in Unison: Using Lists

Python Games. Session 1 By Declan Fox

Table of Contents. 1. Creating a Microsoft Excel Workbook...1 EVALUATION COPY

Nonvisual Arrays and Recursion. by Chris Brown under Prof. Susan Rodger Duke University June 2012

Chapter 2 Visual Basic Interface

1/16/12. CS 112 Introduction to Programming. A Foundation for Programming. (Spring 2012) Lecture #4: Built-in Types of Data. The Computer s View

SUM - This says to add together cells F28 through F35. Notice that it will show your result is

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

ITP 342 Mobile App Dev. Code

DOING MORE WITH EXCEL: MICROSOFT OFFICE 2013

BEGINNING PROBLEM-SOLVING CONCEPTS FOR THE COMPUTER. Chapter 2

Applied Systems Client Network SEMINAR HANDOUT. Document Setup in TAM Changing from Office 2003 to 2007, where ARE things now?

Changing Camera Views! Part 2: Simple Scene Change & Lighting Fixes

= 3 + (5*4) + (1/2)*(4/2)^2.

Operators. Java operators are classified into three categories:

Setting up A Basic Scene in Unity

CS 112 Introduction to Programming

Admin. CS 112 Introduction to Programming. Recap: Java Static Methods. Recap: Decomposition Example. Recap: Static Method Example

CIS 110: Introduction to Computer Programming

CSE 115. Introduction to Computer Science I

Introduction to Events

The Essentials of Alice (Bunny) By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008

Full file at

A variable is a name for a location in memory A variable must be declared

12/15/2008. All about Game Maker. Integrated Development Environment for 2D games Global idea

Make View: Check Code

Outline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Introduction to Computer Science with MakeCode for Minecraft

EXCEL BASICS: MICROSOFT OFFICE 2007

Not For Sale. Glossary

append() function, 66 appending, 65, 97, 296 applications (apps; programs), defined, 2, 296

SMARTBoard. Basic Directions. Part 1 Pages 1-12

Unit 12. Electronic Spreadsheets - Microsoft Excel. Desired Outcomes

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

Animating Objects in Groups: Using Arrays and Lists

Microsoft Excel 2010 Handout

Animating Objects in Groups: Using Arrays and Lists. By Ruthie Tucker under the direction of Professor Susan Rodger Summer 2008

Week 3: Objects, Input and Processing

Chapter 2: Data and Expressions

VirMuF Manual V 0.5 1

SPARK-PL: Introduction

What did we talk about last time? Examples switch statements

Excel 2016 Basics for Windows

1 Getting started with Processing

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

CS11 Java. Fall Lecture 1

WeDo Mars Rover. YOUR CHALLENGE: Working with a partner, collect rock and soil samples from the Martian crust using your Mars Rover Robot.

Use the Move tool to drag A around and see how the automatically constructed objects (like G or the perpendicular and parallel lines) are updated.

Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18

Gloucester County Library System. Excel 2010

GAZIANTEP UNIVERSITY INFORMATICS SECTION SEMETER

ECE 122 Engineering Problem Solving with Java

Microsoft Robotics Studio Walk-through

Skater World: Part Three

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

The Mathcad Workspace 7

Introduction to TURING

Visual Basic 2008 The programming part


Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

animation, and what interface elements the Flash editor contains to help you create and control your animation.

Functions in Excel. Structure of a function: Basic Mathematical Functions. Arithmetic operators: Comparison Operators:

CS112 Lecture: Working with Numbers

Tutorial00. Jumping down the rabbit hole

Adding A Signature To A Photograph By Jerry Koons

Algorithms and Programming I. Lecture#12 Spring 2015

Transcription:

Variables and Functions Chapter 3 3-1

Variables Named storage location in computer s memory Programs may need to store data when running o Stored in a variable 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 Parameter variables o Holds argument that is passed to a called method Class-level variables o Variable that belong to a specific object World-level variables o Variable that belongs to the world 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 o o Name Type Initial value name type value 3-4

Names, Types and Initial Values Variable Names Must be unique within the method Should be meaningful and reflect the variable s purpose Named using camelcase Variable Types Numbers, Boolean, Objects, Other (such as String, Color, or Sound) Initial Value 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 variable area 3-6

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

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

Function Asks a question o Checks a condition o Computes a value Used to get information about o Properties of objects Is snowwoman's face red? o Relationship of one object to another What is distance between lunar robot and rock? o A current condition What keyboard key was pressed?

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

Value What a function returns after it o Asks question o Performs computation Type of value depends on kind of function o In lunar example What is distance of robot to rock? o Number value is expected to be returned Whole number ex: 3 meters Fractional value, ex: 1.2 meters

Types of Values Number o As in example Boolean o true, false String o Slithy Toves Object o snowman, helicopter Position in world o (0, 0, 0) center of an Alice world

Asking User for Input World has three primitive functions that ask for user input Each function is displayed in a dialog box Is it Yes or No? 3-13

Adding Question for Number

Class Primitive Object Functions Objects have different primitive functions from the world 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

Checkpoint What makes a function different from a method? How do you see a list of the 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-17

Creating Math Expressions Math Operators are used to create math expressions Math expressions perform a calculation and return a value Simple math expression o 12 + 2 Operator Description + Addition - Subtraction * Multiplication / Division o Value returned is 14 Operands appear to the right and left of an operator o Example with variables payrate and hoursworked payrate * hoursworked 3-18

Determining Distance Camera angle influences our perception of scene We need assistance with determining distance Example: How many meters does robot need to walk to reach rocks where alien is hiding? o Can use pointofview property Primitive function

Avoiding Collisions When program is run, robot collides with rock o Distance between two objects is measured centerto-center One way to avoid a collision o Reduce calculated distance to object o Use expression to subtract small number (1 or 2) from distance

Expressions in Arguments Math expressions can be used in place of o Fixed value o To adjust value returned by function Click down arrow to get math operation o Adjusts distance to move to not collide with rock

Adding Math Expression in Alice 3-22

Subtracting Functions Two meters subtracted from distance is arbitrary To be more precise, subtract width of rock o But still not accurate Resulting expression subtracts value of one function from value of another function

More Precision The most accurate way to determine distance and to avoid collision o Add half width of both objects subtract from distance Be careful of excessive parentheses

Checkpoint What do the following operators do in most programming languages? o + - * / What does a math expression do? When you use the move to instruction to move one object to another object, why do they collide? o What are multiple methods you can use to avoid this? When can an object be driven into the ground or above the ground when using move to or move toward instructions? 3-25

Working with Strings and Text A string is a sequence of characters Strings represent o Names o Addresses o Messages o etc. 3-26

Asking User to Enter a String World s ask user function can ask user to enter string Function returns the text that the user enters Example displays what user entered in dialog bubble Defines string variable called name Puts contents of name variable in bubble Asks user for name Stores in variable name 3-27

Joining Strings String Concatenation o Joins string a with string b o Strings a and b are arguments o Does not change the values of strings a or b World function o a joined with b Drag a joined with b from string section in World function to where you want to join strings 3-28

Example of a joined with b Hello joined with was only thing added 3-29

Converting Numbers to Strings Sometimes you need to display numbers to user Number needs to be converted to string first Use world functionwhat as a string

Example of what as a string 3-31

3D Text can be added to Alice worlds Found at end of the local gallery Pop up window appears after clicking on it Enter text and font style 3-32

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 o Tutorial 3-5 Using math to avoid collisions, p 132 o Tutorial 3-6, Converting a number variable to a string, p. 141 Answer questions in handout Do lab assignments after handing in answered questions Due one week after assigned with 1 week grace