Midterm Number II -- Astronomy

  1. What is the value of 'venus' after the code runs? ______________________
    int eleven = 11;
    int twenty = 20;
    int venus = eleven / twenty;
  2. How many times does this code draw a line? ___________________________
    int counter = 73;
    while (counter < 10) {
        counter = counter - 1;
        g.drawLine(counter, counter, 20, 20);
    }
  3. How many times does this code draw a string? ________________________
    int counter = 0;
    do {
        g.drawString("Mars", counter, counter);
    } while (counter < 3);
  4. 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);
    }
  5. (Yes/No)Can the same array hold both a String and a float?
  6. Suppose I have a child class called 'Child' and a parent class called 'Parent'.   Which of the following is true?
  7. 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.  ________________________________
  8. (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'!




















  9. (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);
         }
    }
















  10. (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.