CS 120A   Fall 2001,  Instructor:  Jeffrey Horn    QUIZ 1:  Take-Home      Name:  _____________________
handed out Monday, Nov. 5, 2001            

due Wednesday, Nov. 7, 2001  (end-of-day)  in my dept. mailbox, or fax (227-2020), or email, or WebCT, or whatever


  1. How many times will the body of the loop below be executed?  (for partial credit, show the output)

  2. int n;
    n = 250;
    while (n > 0)
       { n -= 15;
         System.out.println("The current value of n is" + n);  
        };

     

  3. What is the output of the following?

  4. int n;
    n = 2;
    while (n < 100
       { n = n*4;
         g.drawString(20,n,"The current value of n is" + n);
        };

  5. Which of the following are valid names for VARIABLES in Java?
    1. "jeff"
    2. "sarah787"
    3. "pushing_an_elephant"
    4. "c_u_later"
    5. "2_out_of_3_aint_bad"
    6. "why_not?"
    7. "that's_why_not"
    8. ")(%&$(%*"
    9. "gjafkjgrqiturq"
  6. Which of the above is a valid METHOD name?
  7. Which of the above is a valid CLASS name?
  8. What is the value of "x" after the following code is executed?

  9. int x;
    x = 2;
    if (12 > 25/2)
       x += 10;
        else x -=5;
  10. Assume the following method is already written, and debugged!  Read the comment to see what it does.  Then write a "paint" method that calls "paintMonster" to draw 10 monsters of increasing size in a diagonal (going down and to the right).
  11. // "paintMonster(x,y,size)" draws a way cool monster centered at position
    //  x,y in the window of Graphics object g, making the monster of size "size"
    //  which is actually about "size" pixels wide, and 2 * size pixels high.
    //  (x,y, and size are all int's here, and the unit is pixels.)
    private void paintMonster(Graphics g, int x, int y, int size)
        {   //assume this part is written, details don't matter!
         }