CS46A Midterm

Exam Rules

After 75 minutes, no submissions will be accepted

  1. Fill in the missing parts in this class.

    26 points

  2. Complete the Problem2 class to draw this image. You must use one or more loops in your solution. You will receive no credit for a solution that draws ten separate shapes without using a loop.

    20 points

  3. Trace the execution of the method call

    addLine("I am")

    at the end of this class. (It's the last method—ignore the methods before it.) Be sure to trace through the loop inside the method. Do NOT trace into addWord.

    Make a column for each local variable. Write new values below to the old ones when they change. Put an X when a local variable is removed.  Make a separate line for each modification.

    Submit a file problem3.txt completing this form:

    words       i   more     ch   j
    -------------------------------
    I am
        

    20 points

  4. Consider these Mystery and MysteryTester classes. You do not need to understand the code. The code has a bug, but you are not asked to find it. This question tests whether you can use the debugger.

    Using the BlueJ debugger, set a breakpoint on the first line inside the addWord method of Mystery.java.

    Run the program until it reaches the breakpoint.

    a) What is the value of word?

    Now set a breakpoint in the first line of the spread method. Run the program until it reaches that breakpoint. Don't clear the other one.

    b) How many more times was the first breakpoint triggered before the second one was reached?

    c) Step through the spread method. How many times do you go inside

          if (i < current.length()) // How many times?

    d) Keep stepping until you reach the end of the for loop. Now enter the eol method. Which button did you use?

    e) What are the values of the instance variables when you reach the last line of the eol method?

    f) Take a screen capture of the debugger window with the instance variables when you are at the last line of eol i.e.

    words = 0; // Take screen capture here

    Submit a file problem4.txt and a file problem4.png containing your screen capture.

    12 points