Midterm #1 -- My Potsy's Revenge
-
Which of the following are legal variable names?
2Liters
PotsyLovesMe
Potsy Loves Me
posty+love
posty_loves_me
-
What is the value of 'a' after this code runs? 'A' is of type float.
_______________
a = 1.0+2.0/3.0+4.0;
-
What is the value of 'a' after this code runs. 'A' is of type int.
__________________
a = 2/3;
-
How many times does this code draw a line? _____________________
int counter ;
for(counter = 0; counter < 4; counter++) {
g.drawLine(counter, counter, 100,
200);
}
-
How many times does this code draw a line? ______________________
int counter;
counter = 999999;
do {
g.drawLine(10,20,30,40);
} while (counter < 1);
-
How many times does this code draw a line? _____________________
int counter;
counter = 1;
while (counter < 10) {
g.drawLine(1,2,3,4);
}
-
Suppose the applet has a bounding box of 500 by 500. In other words,
in the html code you have "heigth=500 width=500". What happens if
you try and draw a rectangle from 200,200 to 700, 700.
-
The program won't compile.
-
The program crashes when you run it.
-
The rectangle never appears.
-
Potsy doesn't like rectangles. He likes squares!
-
Only those parts of the rectangle that fit within the bounding box appear.
-
When is init() called?
-
Once when the program is first started, and NEVER again.
-
Just before connecting to the database.
-
Posty was cooler than Richie!
-
Init code is just used for documentation, to tell readers of the code what's
going on.
-
Every time just before paint() is called, to give variables values as needed
by paint.
-
Fill in the if statement. It should draw the string "Potsy" if
the 'age' is 19 and the 'hairlength' is 3.2 and the 'height' is 67.
if (_____________________________________________________________________________________________)
{
g.drawString("Potsy", 10 20);
}
-
(3 points) Assume that an array 'grades' already exists. It contains
Potsy's grades in his woodworking class. It is of type int, and has
100 elements. Write some code that prints "yes" to the screen if
there a grade of 90 or better anywhere in the array.
-
(3 points) Potsy likes squares! Write me some code that draws a diagonal
line of squares down the screen. I don't care how big you make the
screen, or how big each square is, or how far apart they are. Be
reasonable. You MUST use a loop of some sort, either a for
loop, a while loop, or a do loop.
-
(2 points) Fill in the mouseDown function so that it just redraws the screen
when the mouse is clicked. It need do nothing but redraw the screen.
public boolean mouseDown () {
}
-
(3 points) Potsy would like to know his quiz average. Use the
'grades' array from above to compute his quiz average. Print his
average on the screen.