Presentation is loading. Please wait.

Presentation is loading. Please wait.

Continuous February 16, 2009. Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?

Similar presentations


Presentation on theme: "Continuous February 16, 2009. Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?"— Presentation transcript:

1 Continuous February 16, 2009

2 Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?

3 Test Review What will be printed in the following code? for (int i = 0; i<10; i=1) { print(i + " "); }

4 Test Review What is the test expression so that the following loop prints the line 0 1 2 3 4 int count = 0; while ( ___________ ) { print( count + " " ); count = count + 1; }

5 Test Review Which statement is not true of a variable declaration? Choose one answer. 1. The declaration must be given before the variable is used. 2.The declaration gives a name and a data type for the variable. 3.The declaration gives an initial value to the variable. 4.A variable cannot be used in a program unless it has been declared.

6 Test Review Examples of primitive data types are (Choose one answer.) 1.boolean, int, float, byte, and character 2.blean, int, float, byte, and char 3.boolean, int, floating, byte, and character 4.boolean, int, float, byte, and char

7 Test Review What is the meaning of i++ ?

8 Test Review What is the meaning of i++ ? A variable is What type of looping constructs did we discuss? What data type is appropriate to store the value 5.232?

9 Test Review What is the meaning of i++ ? A variable is What type of looping constructs did we discuss? What data type is appropriate to store the value 5.232?

10 Test Review According to the NC DOT, a Level 2 Limited Provisional license requires that a driver must be at least 16 years old, but less than 18, and there may be no more than one passenger under 21 years of age in the vehicle.

11 Test Review What must the initialization be so that the following fragment prints out the integers -3 -2 -1 ? for ( _______; j < 0; j++ ) println( j );

12 Test Review What must be added so that the following code prints out the even integers 0 2 4 6 8 10? for ( int j = 0; j <= 10; _______ ) println( j );

13 Test Review What must be added so that the following code prints out the even integers 0 2 4 6 8 10? for ( int j = 0; j <= 10; _______ ) println( j );

14 Flow of Control Programs can broadly be classified as being –Procedural Programs are executed once in the order specified by the code varied only by loops and function calls. –Event Driven Programs run continuously responding to input events such as key strokes or mouse clicks.

15 How Do Those Classification Pertain to Our Class All the programs we have written or looked at so far are procedural. Today we look at event driven programs. First event driven program void draw() { frameRate(4); //fps = 4 println(frameCount); }

16 What Happened? About 4 times per second, a number (the frame count) was printed to the console window. Why? –There’s no for loop or while loop? The draw() function is processed continuously by the event handler until another event is triggered or you press the STOP button.

17 More on Why Specifically the draw() function is called 4 times per second since we set the frameRate to 4. Remove the frameRate() line and see what happens. What’s the default frame rate?

18 Next Program float y = 0; void draw() { frameRate(10); line(0, y, 100, y); y = y + 0.5; }

19 How Can We Produce the Following Sketch? Change the line y = y + 0.5; To y = y + 1.5;

20 Background The background doesn’t refresh automatically so lines just accumulate.

21 More with Draw() To clear the window at every frame, pt a background() command at the beginning of draw(). Background doesn’t have to use a constant as its argument, change it to use an expression with y.

22 Can You Add a Conditional to Make the Lines Disappear When They get to the Bottom? float y = 0; float increment = 0.5; void draw() { frameRate(10); background(50+y*2); line(0, y, 100, y); if (y > height) increment *= -1.0; y = y + increment; }

23 setup() For instructions that just need to be run once, use setup(). float y = 0; float increment = 0.5;

24 setup() float y = 0; float increment = 0.5; void setup() { size (100, 100); smooth(); fill(0); } void draw() { frameRate(10); background(50+y*2); line(0, y, 100, y); if (y > height) increment *= -1.0; y = y + increment; }

25 setup() float y = 0; float increment = 0.5; void setup() { size (100, 100); smooth(); fill(0); } void draw() { frameRate(10); background(50+y*2); line(0, y, 100, y); if (y > height) increment *= -1.0; y = y + increment; }

26 Variable Scope What happens if you declare y –At the top –In draw –In setup

27 Scope When a variable will change in each iteration of draw, declare it outside of setup() and draw().

28 Why? When a variable is created within a code block, it can be used only within that block. It will be destroyed with the program leaves the block.

29 In-class Lab Create a shape that moves from one side of the canvas to the other. When it reaches the opposite edge have it reverse direction and continue back and forth endlessly. For maximum credit make sure your code will work if the window size is set differently.


Download ppt "Continuous February 16, 2009. Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?"

Similar presentations


Ads by Google