Problem Solving: Karel and Elementary Graphics

advertisement
Problem Solving: Karel and Elementary Graphics
Final Exam Review
Exam Date: ______________
Exam Time: ______________
Overview
Topics for the exam will include anything that is in the book, in your class notes, or from
your exercises. That means, READ and STUDY your book, notes, and exercises.
The exam includes both objective questions and free-response questions. You will be
asked to write and analyze code. For the free response, you will be permitted to use a
“template” to begin your work.
Broad Topics







Problem solving strategies
Methods and classes
Conditional statements
Loops
Parameters
Variables and user input
Arithmetic and Logical Operators
Review Questions
1. What are the phases in the problem solving process?
2. What are two reasons why making new methods is important?
3. What conditional tests can be used with Karel the Robot? What conditional tests can
be used with graphics?
1
4. When is it appropriate to use an if/else statement? When is it appropriate to use nested
conditions?
5. What are the benefits of looping structures?
6. When is it appropriate to use an iterative loop? When is it appropriate to use a
conditional loop?
7. What are parameters and how do they benefit problem solving?
8. When writing a method that uses parameters, how is the formal parameter list set up?
Give an example
10. What is the difference between a “double” and an “int”?
11. Given the following declarations, determine the result of each statement. If you think
the statement causes an error, say why.
int x1 = 50, y1 = 10, x2 = 90, y2 = 38, radius = 24;
a. int answer = radius / 10;
b. int answer = radius * 0.5;
c. double answer = radius / 4.0;
d. double answer = 1 / 2 * x2;
e. double answer = radius / 2.0;
f. double answer = (y2 – y1)*1.0 / (x2 – x1);
2
12. For the following block of code, a) correct the syntax errors, and b) draw the resulting
window:
import cs.ssa.*;
class Unknown1
{
static public void main (String[] args)
{
SSAWindow canvas = new SSAWindow (500, 300);
int a, b, c;
a = 100;
B = 150
c = 50;
While (c > 0);
{
if (c == 20)
{
canvas.drawOval(a, b, c, c);
}
canvas.drawRect(a, b, c, c)
c = c – 10;
}
}
}
13. For the following block of code, a) correct the syntax errors, and b) draw the resulting
window:
import cs.ssa.*;
class Unknown2
{
static public void main (String[] args)
{
SSAWindow calcWindow = new SSAWindow (500);
int b, e, r;
b = 2;
e = 8
r = 1;
for ( int i = 1; i <= e i++ )
{
r = r * b;
}
GraphicsWindow.drawString( "Here is the result: ", 20, 50 );
calcWindow.drawString(b + " to the " + e + " = " + r, 20, 70 );
}
3
13. If the center of the upper oval is x, y and the radius is “rad”, label the coordinates of
the significant points for drawing the figure:
14. For the following shape, imagine that the center point is at (xC, yC). You are given
“size” as the width of the largest square. Label the coordinates of the significant points
for drawing the figure:
4
Download