CS120 -- The Midterm

  1. Which of the following are legal variable names?  Circle all the legal names.
  2. wear wolf                                   bite                                   fang's mark
    wolf4ever                                   FurCoat                             2LitersOfBlood
  3. Is your name on the test
    1. Yes, it is.
    2. Yes, it will be.
  4. How many lines does this code draw?
  5. int fangmarks = 2;
    while (fangmarks < 10.0) {
         g.drawLine(fangmarks, 10,20,30);
         fangmarks = fangmarks * 2;
    }
  6. Write me a loop of some kind that draws ten lines.  The lines should be (1,1) to (1,99), (2,1) to (1,99), (3,1) to (1,99), (4,1) to (1,99), ......... (10,1) to (1,99).

  7.  

     
     
     
     
     
     
     
     

  8. How do you catch lycanthropy?
    1. Get bit by a wearwolf.
    2. Have wearwolf parents.
    3. Date wearwolves.
    4. Eating broccli.
  9. Which of these statements is true?

  10.           1.The "system" calls paint() when the  screen needs to be redrawn  Our 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.What's the deal with wearwolves and broccli?
  11. Suppose I have an integer variable 'wolfsage'.  Show me a paint procedure that will show the value of 'wolfsage' on the screen.  I don't need a whole program.  Just a paint procedure.

  12.  

     
     
     
     
     

  13. What is one difference between a while loop and a do loop?

  14.  

     
     
     

  15. What's a wearwolf's favorite food?
    1. CS120 students
    2. Wolfsbane
    3. Small black cats that belong to evil witches
    4. Broccli!!!!
  16. (6 points) 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!!!!!

  17.  

     

  18. (6 points) Write me a whole program that does the following.  It should draw a square wolf's face on the screen.  The corners of the wolf's face are at (100,100), (100,200), (200,100), and (200,200).  If someone clicks the mouse on the wolf's face, the face should turn red.  If they click somewhere else, the face should turn blue.  The wolf's face need not be beautiful.  Just a couple of boxes/circles/whatever.