From last time…
•

Libraries, Functions, Active Mode, Interaction!

•

Check the site for a list of inspiration sources!

•

We have a Teaching Assistant:!

! Yifan Wang, yifan@cise.ufl.edu!
! Office Hours: CSE309, 2:00pm–3:00pm
Variables

CAP
What is a variable?
•

An address in memory: 0x0000883A!

•

Variables have a type and a name!

int x;
int y;
float weight;
string introduction;
Memory
int x;
The Primitives
boolean!! ! 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
Common Primitives
boolean!! ! true or false!
int ! ! ! -2147483648 to 2147483647!
float! ! ! 3.14159
Using Variables
1. Declare the variable!

int xposition;

// type name;

2. Initialize the variable!

xposition = 10;

// name = value;
Using Variables
1 & 2. Declare & Initialize the variable!

int xposition = 10;
// type name = value;
Demo Variables
System Variables
mouseX, mouseY
pmouseX, pmouseY
width, height

// sketch dimensions

frameCount, frameRate
displayWidth, displayHeight
dimensions

// screen

key, keyCode, keyPressed
mousePressed

// is it pressed?

mouseButton

// left/center/right
Demo!
System Variables
random() & casting
random(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
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!

5. Variables

  • 1.
    From last time… • Libraries,Functions, Active Mode, Interaction! • Check the site for a list of inspiration sources! • We have a Teaching Assistant:! ! Yifan Wang, yifan@cise.ufl.edu! ! Office Hours: CSE309, 2:00pm–3:00pm
  • 2.
  • 3.
    What is avariable? • An address in memory: 0x0000883A! • Variables have a type and a name! int x; int y; float weight; string introduction;
  • 4.
  • 5.
    The Primitives boolean!! !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
  • 6.
    Common Primitives boolean!! !true or false! int ! ! ! -2147483648 to 2147483647! float! ! ! 3.14159
  • 7.
    Using Variables 1. Declarethe variable! int xposition; // type name; 2. Initialize the variable! xposition = 10; // name = value;
  • 8.
    Using Variables 1 &2. Declare & Initialize the variable! int xposition = 10; // type name = value;
  • 9.
  • 10.
    System Variables mouseX, mouseY pmouseX,pmouseY width, height // sketch dimensions frameCount, frameRate displayWidth, displayHeight dimensions // screen key, keyCode, keyPressed mousePressed // is it pressed? mouseButton // left/center/right
  • 11.
  • 12.
    random() & casting random(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
  • 13.
    For next time… • Mondayis 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!