Final Exams Pt 4 Flashcards

1
Q

Describe the function of a while loop and compare it to a for loop

A

A while loop repeats code until a condition becomes false. In comparison with a for loop, a while loop runs an arbitrary (INCONSISTENT) number of times, while a for loop runs for a fixed number of
times.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Write a while loop that will:
Run as long as a value equals 4

A

while (value == 4)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Write a while loop that will:
Stop when a value equals “quit”

A

while (!value.equals (“quit”))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Write a while loop that will:
Run while a value is more than 100 and a value is ‘y’

A

while (first > 100 && second == ’y’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe what user input is

A

1) interaction between person using program and program.
2) entering data
3) interacting with mouse
4) actions when certain keys are pressed on keyboard.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What types of data can be entered into Processing?

A

The same types that can be declared as variables: int, float, String, char

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Write a line of code to:
Get an integer from the user and store it in a variable

A

int num = getInt(“Please enter an integer”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Write a line of code to:
get a float from the user and store it in a variable

A

float val = getFloat (“Enter any number”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Write a line of code to:
get a word from the user and store it in a variable

A

String word = getString (“Please enter a word”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Describe how keyboard input is different from user input above

A

1) action of pressing key.
2) doesn’t send value to be stored, but creates ACTION that calls keyboard method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What procedures are available for keyboard input? Briefly describe each

A

1) keyPressed() - when key is pressed
2) keyReleased() - when key is released
3) keyTyped() - when printable character is typed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Write code for the following:
(a) Code that draws a SQUARE whenever any key on the keyboard is pressed

A

void keyPressed(){
square(x, y, 100);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Write a code for the following:
Code that will increase a variable by 2 when ‘w’ is pressed and decrease a variable by
3 when ‘s’ is pressed

A

void keyPressed(){
if(keyPressed == ‘w’){
x+=2;
}
if(keyPressed == ‘s’){
x-=3;
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly