Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm Exam 2 Review Fall2006

NOTE! We decided NOT to have any questions concerning GUIs on this exam, so you don't have to study that topic. That topic WILL be on the final exam.

Below are questions like those I plan to ask on Midterm REMOVED (Nov. 3). The exam will consist of 4 or 5 questions like these.

Please do try these questions! Post your answers, questions, comments, concerns, and criticisms on the pages for each question. Those comments, questions, etc. can also be about each others' answers! If someone posts an answer that you don't understand, ask about it! If you see a question here that you know the answer to, don't keep it to yourself – help your fellow students!

I will be reading your answers. Here are the ground rules for the interaction.
  1. If you don't post, neither will I. I will not be posting official solutions to these problems at all! If one of you gets it right, terrific!
  2. I will try to always point out if an answer is wrong. I won't always point out when the answer is right.
  3. I am glad to work with you toward the right answer. I will give hints, and I'm glad to respond to partial guesses.

Unscramble the code

Below are some code segments. The lines of code are scrambled, and some of the curly braces are removed. Put them back in the right order.

a. From (another complete method)

while (current.getNext() != null)
return current;
current = current.getNext();
public LLNode last() {
LLNode current;
current = this;

b. From

new ActionListener() {
JPanel panel2 = new JPanel();;
Sound s = new Sound(FileChooser.getMediaPath("warble-h.wav"));
public void actionPerformed(ActionEvent e) {
JButton button1 = new JButton("Make a sound");

c. From

JButton button1 = new JButton("Make a sound");
JPanel panel2 = new JPanel();
JButton button2 = new JButton("Make a picture");

d. From
(This comment is right - it's meant to give you a headstart.)
   *Collect all the sound from our children FIRST,* then collect from my getNext().

return childSound;
childSound = new Sound(1); /*A default nearly-empty sound*/
node=(CollectableNode) this.getNext();
CollectableNode node;
if (children != null)
Sound childSound;
if (this.getNext() != null)
childSound = children.collect();
public Sound collect(){

Questions, comments, answers at Midterm exam 2 review Fall2006: Unscramble the Code

Draw the Object Structures

Draw the object structures (e.g., boxes and arrows) for the data structures resulting from these methods.
(Note: You can use any notation we used in class to draw the data structure for B.)

A. From

 public void setUp4(){
    Sound s = null;  // For copying in sounds

    s = new Sound(FileChooser.getMediaPath("is.wav"));
    root = new SoundElement(s);

    s = new Sound(FileChooser.getMediaPath("snap-tenth.wav"));
    SoundElement one = new SoundElement(s);

    s = new Sound(FileChooser.getMediaPath("corkpop-tenth.wav"));
    SoundElement two = new SoundElement(s);

    s = new Sound(FileChooser.getMediaPath("clap-q.wav"));
    SoundElement three = new SoundElement(s);


B. From
    public void setUp3() {
    Sound clap = new Sound(FileChooser.getMediaPath("clap-q.wav"));
    Sound chirp = new Sound(FileChooser.getMediaPath("chirp-2.wav"));
    Sound rest = new Sound(FileChooser.getMediaPath("rest-1.wav"));
    Sound snap = new Sound(FileChooser.getMediaPath("snap-tenth.wav"));
    Sound clink = new Sound(FileChooser.getMediaPath("clink-tenth.wav"));
    Sound clave = new Sound(FileChooser.getMediaPath("clave-twentieth.wav"));
    Sound gong = new Sound(FileChooser.getMediaPath("gongb-2.wav"));
    Sound guzdial = new Sound(FileChooser.getMediaPath("guzdial.wav"));
    Sound is = new Sound(FileChooser.getMediaPath("is.wav"));

    root = new SoundBranch();
    SoundNode sn;

    SoundBranch branch1 = new SoundBranch();
    sn = new SoundNode(guzdial.append(is).append(snap));
    sn = new SoundNode(clink.append(snap).append(clave));
    sn = new SoundNode(guzdial.append(is).append(is));

    scaledBranch = new ScaleBranch(2.0);
    sn = new SoundNode(clink.append(clave).append(gong));
    sn = new SoundNode(rest.append(chirp).append(clap));

    SoundBranch branch2 = new SoundBranch();
    sn = new SoundNode(clap.append(is).append(snap));
    sn = new SoundNode(clink.append(snap).append(clave));
    sn = new SoundNode(chirp.append(is).append(is));

    scaledBranch = new ScaleBranch(0.5);
    sn = new SoundNode(guzdial.append(is).append(gong));

    SoundBranch branch3 = new SoundBranch();
    sn = new SoundNode(clap.append(clap).append(clave));
    sn = new SoundNode(snap.append(snap).append(clave));
    sn = new SoundNode(snap.append(snap).append(clave));


Questions, comments, answers at Midterm exam 2 review Fall2006: Draw the Object Structures

What's My Data Structure?

We've talked about several data structures in this class: Arrays, trees, linked lists. Match the data structure to the statement below.

A. "Right, so it takes a while to insert or delete in my middle, but you can't possibly get to a specific piece of me faster!"

B. "Insert and delete into the middle are really fast with me, but I don't DO complexity – no hierarchy for me!"

C. "Organization chart? Sentence diagrams? Verses and chorus in a song? Structure of a scene? I'm your structure!"

Questions, comments, answers at Midterm exam 2 review Fall2006: What's My Data Structure?

Make a Scene

Below is some code that uses PositionedSceneElements to make a scene of a tree, a dog, another tree, and another dog.
public class PSETest {
  public static void main(String [] args) {

    Picture dog = new Picture(FileChooser.getMediaPath("dog-blue.jpg"));
    PositionedSceneElement dognode = new PositionedSceneElement(dog);
    PositionedSceneElement dognode2 = new PositionedSceneElement(dog);

    Picture tree = new Picture(FileChooser.getMediaPath("tree-blue.jpg"));
    PositionedSceneElement treenode = new PositionedSceneElement(tree);
    PositionedSceneElement treenode2 = new PositionedSceneElement(tree);

    treenode.setNext(dognode); dognode.setNext(treenode2);

    Picture bg = new Picture(400,400);


Write another version that has a dog scaled to 0.25 of its original size, then three houses ("house-blue.jpg"), then three trees, all composed onto the "jungle.jpg" background.

Questions, comments, answers at Midterm exam 2 review Fall2006: Make a Scene

Java, Java, Java, says George

Answer the following questions about Java (the language, not the drink):

A. BorderLayout and FlowLayout are two of what kind of thing? How do they differ?

B. What's an Event and what do they have to do with ActionListeners?

C. "Casting"? I don't think Java has anything to do with broken legs or fishing, so what is it and when do you need it?

Questions, comments, answers at Midterm exam 2 review Fall2006: Java, Java, Java, says George

And a One and a Two

Below is the code from SongNode for weave. Write a new method weaveTwo which takes two input SongNode instances (one and two) and an int named count. For count times, insertAfter one copy of one and two copies of two.
If you had a list "F->G", and you said nodeF.weaveOneAndTwo("A","B",3), you would expect to get "F->A->B->B->A->B->B->A->B->B->G".
A->B->B (a one A and a two B), three times, got inserted after F.

   * Weave the input phrase count times every skipAmount nodes
   * @param nextOne node to be copied into the list
   * @param count how many times to copy
   * @param skipAmount how many nodes to skip per weave
  public void weave(SongNode nextOne, int count, int skipAmount)
    SongNode current = this; // Start from here
    SongNode copy; // Where we keep the one to be weaved in
    SongNode oldNext; // Need this to insert properly
    int skipped; // Number skipped currently

    for (int i=1; i <= count; i++)
      copy = nextOne.copyNode(); // Make a copy

      //Skip skipAmount nodes
      skipped = 1;
      while (( != null) && (skipped < skipAmount))
        current =;

      if ( == null) // Did we actually get to the end early?
        break; // Leave the loop

      oldNext =; // Save its next
      current.insertAfter(copy); // Insert the copy after this one
      current = oldNext; // Continue on with the rest

Questions, comments, and answers at Midterm Exam2 Review Fall2006: And a One and a Two


Understanding inheritance

When we introduced the linked list class LLNode, we were able to edit the classes that handled pictures and sounds that also implemented linked list functionality. Why did we do that and how did we do that?

Questions, comments, and answers at Midterm Exam2 Review Fall2006: Understanding inheritance

Links to this Page