Upcoming SlideShare
×

# 5. Variables

212 views

Published on

Published in: Education
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

### 5. Variables

1. 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.uﬂ.edu! ! Ofﬁce Hours: CSE309, 2:00pm–3:00pm
2. 2. Variables CAP
3. 3. What is a variable? • An address in memory: 0x0000883A! • Variables have a type and a name! int x; int y; float weight; string introduction;
4. 4. Memory int x;
5. 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! ! ! ﬂoat with more decimal places
6. 6. Common Primitives boolean!! ! true or false! int ! ! ! -2147483648 to 2147483647! float! ! ! 3.14159
7. 7. Using Variables 1. Declare the variable! int xposition; // type name; 2. Initialize the variable! xposition = 10; // name = value;
8. 8. Using Variables 1 & 2. Declare & Initialize the variable! int xposition = 10; // type name = value;
9. 9. Demo Variables
10. 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. 11. Demo! System Variables
12. 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. 13. 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!