Date post: | 31-Dec-2015 |
Category: |
Documents |
Upload: | shawn-johns |
View: | 212 times |
Download: | 0 times |
Test Review
• What expression represents the zip car eligibility rules of at least 18 years old and no incidents?
Test Review
• What will be printed in the following code?
for (int i = 0; i<10; i=1) {
print(i + " ");
}
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;}
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.
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
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?
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?
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.
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 );
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 );
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 );
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.
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);
}
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.
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?
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.
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;}
setup()
• For instructions that just need to be run once, use setup().
• float y = 0;
• float increment = 0.5;
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;}
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;}
Scope
• When a variable will change in each iteration of draw, declare it outside of setup() and draw().
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.