CS120 -- The Final
(Luv Theme)
  1. Which of the following are legal variable names? (Circle all that are O.K.)
  2. 4ever TrueLove True   Love Romeo+Juliette
  3. What is the value of numDatesPerYear after this code runs? ________________

  4. int dates = 3;
    int years = 4;
    int numDatesPerYear = dates / years;
  5. How many times does this code draw a line? ____________________________________

  6. boolean love = true;
    int i = 20;
    do {
           i++;
           g.drawLine(100-i, 50+i, 2*i, 300-i*5);
    } while (love == false);
  7. How many times does this code draw a line? ____________________________________

  8. int i = 10;
    while (i != 1){
           i++;
           g.drawLine(100-i, 50+i, 2*i, 300-i*5);
     }
  9. What is the value of count after this code runs? _____________________

  10. int count = 0, index = 0;
    for(index = 10; index < 0; index = index * 2) {
        count = count + 1;
    }
  11. Which of these statements is true?

  12.     1.The "system" calls paint() when the  screen needs to be redrawn  Or code only call repaint().
        2.The "system" calls repaint() when the screen needs to be redrawn  Our code only call paint().
        3.We can call paint() and repaint() any time we want.
        4.Love and the ocean.  What a combination!
  13. Suppose the applet has a bounding box of 300 by 300.  In other words, in the html code you have "heigth=300 width=300".  What happens if you try and draw a rectangle from 200,200  to 700, 700.

  14.     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.
  15. Suppose you run the four lines of graphics code below.  What will you see?

  16.       g.setColor(Color.red);
          g.fillRect(50,50,10,10);
          g.setColor(Color.black);
          g.fillRect(10,10,100,100);
        1.Two rectangles that overlap producing a striped pattern.  (JAIL CLOTHES!!)
        2.A small red filled rectangle on top of a large black rectangle.
        3.Two rectangles that overlap on their corners.
        4.A large black filled rectangle.  The red rectangle is erased.
  17. (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.

 
 
 
 
 
 
  1. ( 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)? ______________________
           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 EventPanel {
             one o;
             three t;
             two() {
                 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);
             }
         }
  1. (3 pts) Write a whole program that computes 10!.  That is 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1.  It should print the answer on the screen.  YOU MUST USE A LOOP!!!!! Show me the program running.

  2.  

     
     
     

  3. (3 pts) Write me a whole program that counts the number of times the user clicks the mouse.  For instance, if the user has clicked the mouse once, the program should say '1'.  If the user has clicked the mouse ten times, the program should say '10'.  Show me the program running.