5. variables

13
From last time… Libraries, Functions, Active Mode, Interaction Check the site for a list of inspiration sources We have a Teaching Assistant: Yifan Wang, [email protected]fl.edu Office Hours: CSE309, 2:00pm–3:00pm

Upload: joseph-murphy

Post on 15-May-2015

86 views

Category:

Education


0 download

TRANSCRIPT

Page 1: 5. Variables

From last time…• Libraries, Functions, Active Mode, Interaction!

• Check the site for a list of inspiration sources!

• We have a Teaching Assistant:!

! Yifan Wang, [email protected]!

! Office Hours: CSE309, 2:00pm–3:00pm

Page 2: 5. Variables

CAP 3032

Variables

Page 3: 5. Variables

What is a variable?• An address in memory: 0x0000883A!

• Variables have a type and a name! int x; int y; float weight; string introduction;

Page 4: 5. Variables

Memory

int x;

Page 5: 5. Variables

The Primitivesboolean!! ! true or false!char! ! ! ! ‘a’ ‘b’ ‘c’!byte! ! ! ! -128 to 127 short! ! ! -32,768 to 32,767!int ! ! ! -2147483648 to 2147483647!long! ! ! ! larger numbers!!float! ! ! 3.14159!double! ! ! float with more decimal places

Page 6: 5. Variables

Common Primitives

boolean!! ! true or false!int ! ! ! -2147483648 to 2147483647!float! ! ! 3.14159

Page 7: 5. Variables

Using Variables

1. Declare the variable! int xposition; // type name;

2. Initialize the variable! xposition = 10; // name = value;

Page 8: 5. Variables

Using Variables

1 & 2. Declare & Initialize the variable! int xposition = 10; // type name = value;

Page 9: 5. Variables

Demo Variables

Page 10: 5. Variables

System VariablesmouseX, mouseY

pmouseX, pmouseY

width, height // sketch dimensions

frameCount, frameRate

displayWidth, displayHeight // screen dimensions

key, keyCode, keyPressed

mousePressed // is it pressed?

mouseButton // left/center/right

Page 11: 5. Variables

Demo!System Variables

Page 12: 5. Variables

random() & castingrandom(j) // from 0 to j

random(j,k) // from j to k

float r = random(24);

int r = random(24); // needs to be cast!

int r = int(random(24)); // int() method

int r = (int) random(24); // Java cast

Page 13: 5. Variables

For next time…• Monday is Martin Luther King, Jr. Day!

• Read Shiffman, p. 59–70 (Conditionals I)!

• Project Proposals due on Wed, January 22

Quiz• Closed book, 25 minutes, good luck!