Bank Robbery Quiz

1) Which of the following are legal variable names? Circle all that ARE legal.
  2) What is the value of result after this code runs? _________________________
  3) How many times does this code draw a line? ___________________
  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.
  1. The program won't compile.
  2. The program crashes when you run it.
  3. The rectangle never appears.
  4. Only those parts of the rectange that fit within the bounding box appear.

  5.  
5) What is the value of bank after this code runs? ____________  6) What is the value of robber after this code runs? _____________ 7) How many lines does this code draw? _____________________________ 8) How many lines does this code draw? _____________________________

    for(float x_coord = 72; j < 80; j -= 1.0) {
          g.drawLine(x_coord, 1, x_coord, 100);
    }
     

9) Which of these statements is true?
  1. The "system" calls paint() when it wants the screen repainted.  Applets we write only call repaint().
  2. The "system" calls repaint() when it wants the scren repainted.  Applets we write only call paint().
  3. We can call paint() and repaint any time we want and with whatever arguments we want?
  4. Elvis still lives!!!!
10) When is init() called?
  1. Once when the program is first started.
  2. Every time just before paint() is called.
  3. Just before connecting to the database.
  4. Init code is just used for documentation.
11) All are programs start off with the line import java.awt.*;  Why?
  1. This is a comment (documentation) line telling the programmer the code is in Java, and not some other language like C or Pascal.
  2. This is a comment telling the compiler to compile this code like Java, and not like C or Pascal.
  3. This line makes available a whole bunch of commands, like drawLine and setColor.
  4. This line tells the compiler we are compiling a Java pplet, and not a  Java application.
13) What does this code draw? 14) Fill in the blank so that the body of the if statement is executed only when value of cash is 12 or the value of cash is less than zero. 15) Which of the following are valid types?  Circle all that apply. 16) Which of the following assignment statements is correct? 17)  What is the value of shoot after the assignment statement? ___________________________ 18) Suppose you run the four lines of graphics code below.  What will you see?
    g.setColor(Color.red);
    g.drawFilledRect(50,50,10,10);
    g.setColor(Color.black);
    g.drawFilledRect(10,10,100,100);
  1. A small red filled rectangle on top of a large black rectangle.
  2. A large black filled rectangle.  The red rectangle is erased.
  3. Two rectangles that overlap on their corners.
  4. Two rectangles that overlap producing a striped pattern.  (JAIL CLOTHES!!)
19) When is mouseDown() called?
  1. When the user moves the mouse through the applet.
  2. When the user clicks the mouse upon the applet.
  3. When the user, with the mouse button held down, moves the mouse through the applet.
  4. When the screen needs to be repainted but the mouse is obscuring part of the applet.
  5. D.B. Cooper is still alive!!
20)  What does the HTML code do?
  1. Tells the browser what applet to run and what language the applet is in (C or Pascal, etc).
  2. Tells the browser what bank to rob and how much money to take.
  3. Tells the browser what applet to run and how big to make the window (bounding box).
  4. Tells the browser what applet to run and what color the background of the applet should be.