Midterm #1 -- My Potsy's Revenge

 
 
  1. Which of the following are legal variable names?
    2Liters                            PotsyLovesMe                                Potsy Loves Me
    posty+love                         posty_loves_me
  2. What is the value of 'a' after this code runs? 'A' is of type float.  _______________
    a = 1.0+2.0/3.0+4.0;
  3. What is the value of 'a' after this code runs.  'A' is of type int.   __________________
    a = 2/3;
  4. How many times does this code draw a line?   _____________________
    int counter ;
    for(counter = 0; counter < 4; counter++) {
           g.drawLine(counter, counter, 100, 200);
    }
  5. How many times does this code draw a line?  ______________________
    int counter;
    counter = 999999;
    do {
          g.drawLine(10,20,30,40);
    } while (counter < 1);
  6. How many times does this code draw a line? _____________________
    int counter;
    counter = 1;
    while (counter < 10) {
         g.drawLine(1,2,3,4);
    }
  7. 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.
    1. The program won't compile.
    2. The program crashes when you run it.
    3. The rectangle never appears.
    4. Potsy doesn't like rectangles.  He likes squares!
    5. Only those parts of the rectangle that fit within the bounding box appear.
  8. When is init() called?
    1. Once when the program is first started, and NEVER again.
    2. Just before connecting to the database.
    3. Posty was cooler than Richie!
    4. Init code is just used for documentation, to tell readers of the code what's going on.
    5. Every time just before paint() is called, to give variables values as needed by paint.
  9. 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);
    }
  10. (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.  














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






  12. (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 () {





    }
  13. (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.