Short Answer Practice Problems
This week's writing session will start with a physical sheet of paper
containing some subset of these questions, or questions nearly identical
to these questions.
1. Fill in each blank with Model, View, or Controller:
A) The ________________ responds to keyboard, mouse, timer and other events
and updates the model.
B) The ________________ draws the app using the values in the model.
C) The ________________ contains all the data we need for the animation.
D) Controllers can only update the ________________, they cannot update
E) The view can never call the controller functions, and the view also
can never update the ________________.
2. Fill in the blanks with the appropriate values for event.key:
User types: event.key value:
The enter key (aka return) ________________
The space key (aka the space bar) ________________
The left arrow key ________________
The # sign (shift-3) ________________
3. True or False:
A) Your code never directly calls redrawAll (the view) or event handlers
like keyPressed (the controllers) -- these are called for you by the
B) An MVC Violation occurs if you try to update the model while drawing.
C) If the user presses the mouse, the animation framework will first call
mousePressed (the controller), and when that call has completely finished,
only then will the animation framework call redrawAll (the view).
4. Fill in the blank:
A) If we set app.timerDelay to 50, then we will get roughly ________________
calls to timerFired per second.
B) In our grid example, getCell is also known as ______________________,
because it takes (x,y) values and converts them to row,col values.
C) In our grid example, getCellBounds is also known as ______________________,
because it takes row,col values and converts them to (x,y) values.
D) In our grid example, if we set app.rows and app.cols both to 2 in appStarted,
and then we clicked the mouse near the top-right corner of the canvas,
then app.selection would be set to ______________________.
5. Very short answers:
A) Consider this code excerpt from doStep in our bouncing square example:
if app.squareLeft < 0:
# if so, reverse!
app.squareLeft = 0
app.dx = -app.dx
Very briefly, why do we set app.squareLeft = 0?
B) In our snake example, why do we use app.waitingForFirstKeyPress?
C) In our snake example, in takeStep, we check if ((newRow, newCol) in app.snake)).
Very briefly, what situation does this test for?
D) In our snake example, placeFood includes a 'while' loop. Very briefly,
what is the purpose of this loop?
6. In our snake example, mark each of the following with M, V, or C if it is
from the Model, View, or Controller: