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? ____________________________________
boolean love = true;
int i = 20;
do {
i++;
g.drawLine(100-i, 50+i, 2*i,
300-i*5);
} while (love == false);
-
How many times does this code draw a line? ____________________________________
int i = 10;
while (i != 1){
i++;
g.drawLine(100-i, 50+i, 2*i,
300-i*5);
}
-
What is the value of count after this code runs? _____________________
int count = 0, index = 0;
for(index = 10; index < 0; index = index * 2) {
count = count + 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,
in the html code you have "heigth=300 width=300". 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.
-
(3 pts) 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'. Show me the program
running.