Vampires in Love -- A CS120 Test
  1. Why do vampires fall in love?
    1. Everyone needs love
    2. Vampires are human too.
    3. Blood
    4. What a silly question!!
  2. What is the value of 'a' after this code runs.  'a' is of type INT. __________________________
    a = 3/4 + 2/1 +0;
  3. What is the value of 'a' after this code runs.  'a' is of type INT. ___________________________
    a = (int)(3.0 / 4.0) + 2.0 / 1.0 + 0.0);
  4. Write me an if statement.  Fill in the blank below so that the text is printed only if the variable 'age' is between 13 and 19 inclusive.  In other words, only if the vampire is a teenager.
    if (___________________________________________________________________) 
    {
                g.drawString("The Vampire is a teenager", 100, 200);
    }
  5. What is the first part of your program to run?
    1. The constructor for the main class.
    2. The paint procedure for the main class.
    3. The MousePressed function for the main class.
    4. None of the above!
  6. Suppose the applet has a bounding box of 300 by 300.  What happens if you try and draw a rectangle from 200,200  to 700, 700.

  7.           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.
  8. Is your name on the test?
    1. Yes, it is.
    2. Yes, it will be.
  9. (2 points) Write me a Java PROGRAM that draws the words "Vampires Byte" in RED on the screen.






  10. (3 points) Write me a Java PAINT PROCEDURE that draws the words "Buffy was a chearleader" one hundred times, each time in a different spot on the screen.  you must use a loop of some kind.








  11. (3 points) Suppose the screen is 400 x 400.  Write me a Java PROGRAM that draws a red dot on the screen.  When the user clicks the mouse, the red dot moves to be where the user clicked.










  12. How much blood can you loose before you get worried?

  13.       1) a drop
          2) a pint
          3) a gallon
          4) I don't need blood; I'm a creature of the night.
  14. How many times does the first loop run?  How many times does it print "Armand"? _________________
  15. How many times does the second loop run?  How many times does it print "Buffy"? _________________
  16. How many times does the for loop run?  How many times does it print "Jackel"? ____________________
  17. How many times does the program draw the string "Outer + Inner"? _____________________________
  18. What happens when the mouse is clicked?

import java.awt.*;
class control extends MyPanel { 
  
    public boolean mousePressed(MouseEvent e) { 
       repaint();
    } 
    public void paint(Graphics g) { 
  
        // first loop 
        int a = 10; 
        int b = 5; 
        while (a < 5 && b < 3) { 
            g.printString("Armand " + a, a, a); 
            a++; 
        } 

        // second loop 
        int c = 10;
        do { 
            g.drawString("Buffy", 100, 200); 
            c = 3; 
        } while (c = 12); 

        // the simple for loop 
        int d; 
        for(d = 0; d < 5; d++ ) { 
            g.drawString("Jackel", d*20, d*20); 
        } 

        // the nested loops 
        inner = 0; 
        outer = 0; 
        while(outer < 2) { 
            do { 
                int total = outer+inner; 
                g.drawString("Outer plus Inner"+total, total*40, 10); 
                inner++; 
            } while (inner < 1); 
            outer++; 
        } 
    }