Midterm Number II -- Astronomy
-
What is the value of 'venus' after the code runs? ______________________
int eleven = 11;
int twenty = 20;
int venus = eleven / twenty;
-
How many times does this code draw a line? ___________________________
int counter = 73;
while (counter < 10) {
counter = counter - 1;
g.drawLine(counter, counter, 20, 20);
}
-
How many times does this code draw a string? ________________________
int counter = 0;
do {
g.drawString("Mars", counter, counter);
} while (counter < 3);
-
Fill in the body of the if statement so that 'Uranus' is printed only if
at least one of the following two sentences is true. Age is more
than 20 but height is less than 10. Age is more than 50 and height
is more than 30.
if (__________________________________________________________) {
g.drawString("Uranus", 10,10);
}
-
(Yes/No)Can the same array hold both a String and a float?
-
Suppose I have a child class called 'Child' and a parent class called 'Parent'.
Which of the following is true?
-
The parents paint() is called by the system, and so is the childs's paint().
-
The child's paint is called by the system, which calls the parents paint.
-
The parents paint is called by the system, which calls the childs paint.
-
None of these classes paints are called by the system.
-
What is the name of the constructor for a class called Mercury? The
moon is full. The month is April. The computer is an IBM PC.
The mouse has only two buttons. ________________________________
-
(3 points) Write me a child class 'Saturn'. It should draw something
that looks like Saturn (a planet with a ring: A sphere with a circle
around it). The class should have a constructor and a paint.
It need have nothing else. I should be able to have a Saturn appear
at any reasonable (x,y) coordinates! DON'T MAKE ME A WHOLE PROGRAM,
JUST THE CHILD CLASS 'Saturn'!
-
(3 points) Below is a child class 'Rocket'. Write me main class (a
parent class) that put 3 rockets on the screen, at (100,100), (200,
200), and (300,300). It should at the top of the screen say 'Off
to Mars!".
class Rocket {
int x,y;
Rocket(int xstart, ystart) {
x = xstart;
y = ystart;
}
public void paint(Graphics g) {
g.drawLine(x,y,x-5,y+10);
g.drawLine(x-5,y+10,x+5, y+10);
g.drawLine(x+5,y+10,x,y);
}
}
-
(3 points) There exists an array 'Jupiter'. It has 100 floats.
Write me a paint() that prints the LARGEST element of Jupiter on the
screen.