CS 120 -- An Underwater Test


1)  Is your name on the test?
    a) Yes it is.
    b)Yes it will be.


2) Write me a loop that draws the words "Subs are boats not ships!" on (10,20) (10, 40), (10, 60), (10, 80), (10, 100), (10,120), (10, 140).
You MUST use a loop.







3) Write me a loop that draws the words "Torpedoes can turn" on (20,20), (40,40), (60,60), (80,80), (100,100), (120, 120), (140,140).









4) Write me code that draws "Sinking is fun" only if x == 24 OR y = 32.










5) What propelled the first submarine
   a) Nuclear power
   b) Steam engine
   c) Batteries
   d) Guy turning a paddle
   e) None of the above

6) What does the word 'scope' mean?


7) How can you draw a circle from inside mouseClicked()?




8) Here is a for loop.  Write the same thing using a while loop.
   for(int i = 1; i < 200; i = i + 12)
{
g.drawString("Anyone can buy a submarine", 20, 10*i);
}


9) I want to tell if someone has pressed the up arrow key.  How do I do this?
   a) Using mouseClicked()
   b) Using getKeyTyped()
   c) Using 'implements Applet'.
   d) Using '->'.
   e) It's not practically possible from Java.
   f) None of the above


10) Why did German submariners in WWII wear black underwear?
  a) Makes them harder to see at night.
  b) Germany had a lack of white cloth during the war.
  c) Tradition going back to Kaiser Wilhelm I.
  d) The black die absorbed battery acid.
  e) None of the above

11) (Yes/No) Can you use mouseClicked() without a constructor?

12) We fire the torpedo if the heading is between 100 and 120 and the speed is less than 35.  Write some code that draws "Torps away" if these variables have the correct values.

 



Chose any eight points of the programs below.  Do them.  Show me.  Live a happy life!

a) Counts the number of mouse clicks. (2 points)
b) Computes 1/2 + 1/3 + 1/4 + 1/5 + 1/6 ... 1/100.  You MUST use a loop. (4 points)
c) Draws a submarine where you click the mouse (3 points).
d) Prints "Going Up" when you press the 'u' key, and "Going Down" when you press the 'd' key. (4 points)
e) Draws 30 rectangles, one side the other.  You must use a loop (4 points)
f) Picks a random number between 0 ... 1 and does so 100 times.  Print the numer of times you get a zero. (4 points)
g) Draws a submarine.  When you hit an arrow key, the sub moves in that direction. (4 points)
h) Waits for you to type a letter.  It draws that letter at least ten times. (3 points)
i) Like 'h' above, but it FILLS the screen with that letter (1 more, 4 total)