CS 120 -- Final Exam -- The Dog Days of Summer

(If you don't understand some question, then come ask me.)
  1. When does paint() get called?
    1. When the screen needs to be repainted
    2. When the user clicks on the mouse.
    3. When the user types a key.
    4. None of the above.
  2. When does mouseDown() get called?
    1. When the screen needs to be repainted.
    2. When the user clicks on the mouse.
    3. When the user types a key.
    4. None of the above.
  3. When does init() get called?
    1. When the screen needs to be repainted.
    2. When the user clicks on the mouse.
    3. When the user types a key.
    4. None of the above.
  4. Suppose that both a parent class and a child class have a mouseDown().  Which gets called automatically?
    1. The parent's.
    2. The child's
    3. Depends on where the mouse is.
    4. Neither
  5. (True/False) All classes, even the main class that extends java.applet.Applet, should have a constructor.
  6. How many floats does the following code allocate? _______________
    summer = new float [5][5][2];
  7. What is the value of 'skidoo' after this code finishes? _______________
    int skidoo = 5/3;
  8. What is the value of 'beach' after this code finishes? _________________
    int beach = 0;
    while (beach > 10) {
        beach++;
    }
  9. What did Bill Clinton say to the cat from Green Eggs and Ham?
    1. Hey, are you going to finish that?
    2. Uhh, I thought that no one else liked 'Arkansaw Eggs'.
    3. So,  Monica Lewinski is your cook too.
    4. Looks like Hillary early in tyhe morning.
  10. (2 points) Suppose that I have an array of floats named 'grades'.  This is a two dimentional array.  The value of grade[x][y] is the score that student number 'x'  got on test number 'y'.  For example, if grade[3][5] == 72, then student number 3 got a 72 on test 5.  Write me a paint function that prints the average score for student number 1. 












  11. (2 points) The grades arrays is as above.  Write me a paint function that prints the highest grade anyone got on any test.










  12. ( 3 points) Looking at the code below ....
    Where is the first line drawn (at what coordinates)? _______________
    Where is the first oval drawn (at what coordinates)? __________________
    Where does the text appear (at what coordinates)? ______________________

  13. import java.awt.*;
    public class one {
        int x, y;
        one(startx, starty) {
            x = startx, y = starty;
        }
        public void paint(Graphics g) {
            g.drawLine(x,y,10,10);
        }
    public class two extends java.applet.Applet {
        one o; 
        three t;
        init() {
            o = new one(100,200);
            t = new three(300,400);
        }
        public void paint(Graphics g) {
            o.paint(g);
            t.paint(g);
        }
    }
    public class three {
        int a,b;
        three(int newa, int newb) {
            a = newa; b = newb;
        }
        public void paint(Grapics g) {
            g.drawLine(a+100, b+100, 10,10);
            g.drawOval(a,b,100,100):
            g.drawString("Beach Boys", a/2, b/2);
        }
    }

  14.  




  15. (3 points) Below is a child class that puts a symbol on the screen.  Using this child class, write me a parent class that draws one symbol wherever the user has last clicked.  There should always be exactly one symbol on the screen at any moment.  The symbol should start at location (100,200).
    public class symbol {
        Color c;
        int x,y;
        symbol(Color startColor) {
            c = startColor;
        }
        public void move(int newx, int newy) {
            x = newx; y = newy;
        }
        public void paint(Graphics q) {
            q.drawLine(x-5,y-5,10,10);
            q.drawLine(x+5,y-5,10,10);
        }













  16. (5 points)  Write me a whole program that puts a small dot on the screen everywhere the user clicks the mouse.  There should be no grid; the user should be able to click anywhere on the screen and have a dot appear.  If the user has clicked multiple times, then there should be multiple dots.