Download presentation

Presentation is loading. Please wait.

Published byJorden Littlejohn Modified over 2 years ago

1
15-101 Built-in Functions & Arithmetic Expressions

2
A curupira is playing soccer in the rainforest. The curupira has a soccer ball and will kick the soccer ball toward a pond in the forest. Each kick causes the soccer ball to move forward a random distance. If the curupira gets the soccer ball in the water, the curupira scores a point and does a dance, or else he disappears in disgust Recall :

3
To start Download and open the world you were working on from last session: - or - CurupiraSoccerRunToObject.a3p

4
Where we left off Working on running to the soccer ball Do in order curupira runs to soccer ball curupira kicks the soccer ball a random distance If soccer ball is in the water, score 1 point curupira dances else curupira disappears

5
Our implementation Curupira moves forward, but how far? How can we be sure that 1 meter is the correct distance?

6
Curupira does not run far enough

7
In the PenguinBowling project, the penguin was positioned exactly 1 m from the pen – a known distance. pushObject procedure moves this Penguin object forward 1 meter to collide with the target object In the CurupiraSoccer project, the distance between the soccer ball and the curupira is unknown. Known vs Unknown Distance

8
Functions A function asks a question (to check a condition or compute a value). In Alice, a function is used to get the information we need concerning the properties of objects Is the water blue? the relationship of one object to another What is the distance between the curupira and the soccer ball?

9
Alice 3 Methods Panel Performs an action; does NOT compute and return a value Computes and returns a value; does NOT perform an action Sets or gets a value that is stored in a property variable.

10
Return a value of a specific data type Boolean Decimal Number Joints String Built-in functional methods

11
Calling a functional method We use the getDistanceTo function to determine the distance between the curupira and the

12
Calling a functional method Video demonstration of adding getDistanceToTile

13
Calling a functional method A call to a function is embedded within a larger statement (that is, a call to a function is NOT a syntactically complete statement) Example: Calling getDistanceTo The return value (distance value returned by the function) is used as an argument in the move statement

14
Problem: Collision When our program is run, the curupira seems to move through the ball – too much collision.

15
The problem is that distance between two objects is measured center-to-center. One way to solve this problem is to subtract a small number from the distance.

16
Arithmetic Expressions Traditional math and formula computations are implemented as arithmetic expressions in a computer program. An arithmetic expression – is a combination of operators and operands – evaluates to a numeric value

17
A numeric operand can be either A whole number (integer) Or a floating pt number (decimal number).

18
Arithmetic operators are symbols that c an easily be typed on a keyboard Addition+ Subtraction- Multiplication* Division/ Remainder (mod)%

19
Arithmetic expressions in Alice Click pull-down menu arrow for getDistanceTo and select Math Build expression from the cascading menus.

20
Arithmetic expressions in Alice Video demonstration of building an arithmetic expression

21
Binary operation Cascading menus assume a binary operation Operand Operator Operand Resulting statement:

22
Complete runToBall procedure

23
Curupira does not move through the soccer ball

Similar presentations

Presentation is loading. Please wait....

OK

Doing math In java.

Doing math In java.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on osteosarcoma Ppt on l&t finance holdings stock price Ppt on solid dielectrics pdf Edit ppt on iphone Ppt on credit policy variables Ppt on biogeochemical cycle carbon cycle The heart anatomy and physiology ppt on cells Ppt on paintings and photographs related to colonial period food Ppt on business process management Ppt on earth and space science