CS120 -- The Final
(Luv Theme)
-
Which of the following are legal variable names? (Circle all that are O.K.)
4ever |
TrueLove |
True Love |
Romeo+Juliette |
-
What is the value of numDatesPerYear after this code runs? ________________
int dates = 3;
int years = 4;
int numDatesPerYear = dates / years;
-
How many times does this code draw a line? ____________________________________
int luv = 20;
while (luv > 30 {
i++;
g.drawLine(100-i, 50+i, 2*i,
300-i*5);
}
-
How many times does this code draw a line? ____________________________________
int smooch = 10;
while (smooch != 1){
smoch++;
g.drawLine(100-smooch, 50+smooch,
2*smooch, 300-smooch*5);
}
-
Write me a for loop that draws little ovals at (1,100), (10,100), (20,100),
(30, 100) .... (100,100).
-
What is the value of hunnyMoon after this code runs? _____________________
int wedding = 0, hunnyMoon = 0;
for(wedding = 10; wedding < 0; wedding = wedding * 2) {
hunnyMoon = hunnyMoon + 1;
}
-
Which of these statements is true?
1.The "system" calls paint() when the screen
needs to be redrawn Or code only call repaint().
2.The "system" calls repaint() when the screen needs
to be redrawn Our code only call paint().
3.We can call paint() and repaint() any time we
want.
4.Love and the ocean. What a combination!
-
Suppose the applet has a bounding box of 300 by 300. In other words,
the Java "screen" is 300x300. What happens if you try and draw a
rectangle from 200,200 to 700, 700.
1.The compiler will complain.
2. The rectangle is never drawn; the drawline is
ignored.
3.A run time exception is generated/
4.You get a rectangle from 200,200 to 300,300.
-
Suppose you run the four lines of graphics code below. What will
you see?
g.setColor(Color.red);
g.fillRect(50,50,10,10);
g.setColor(Color.black);
g.fillRect(10,10,100,100);
1.Two rectangles that overlap producing a striped
pattern. (JAIL CLOTHES!!)
2.A small red filled rectangle on top of a large
black rectangle.
3.Two rectangles that overlap on their corners.
4.A large black filled rectangle. The red
rectangle is erased.
-
(3 pts) Write a whole program that computes 10!. That is 10
* 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1. It should print the answer on
the screen. YOU MUST USE A LOOP!!!!! Show me the program running.
-
(4 pts) For 2 points write me a whole program that counts the number
of times the user clicks the mouse. For instance, if the user has
clicked the mouse once, the program should say '1'. If the user has
clicked the mouse ten times, the program should say '10'.
For 4 points have it only count clicks on the upper left corner of the
screen. Show me the program running.