Change Contents of the Bubble
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm Exam 2 Review Sp2006

Below are questions like those I plan to ask on Midterm #2 (March 31). 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 Picture.java (a complete method)

for (int x=0; x getWidth(); x++)
topPixel = getPixel(x,(mirrorPoint - y));
public void mirrorHorizontalBottomToTop()
bottomPixel = getPixel(x,(mirrorPoint + y));
for (int y=1; y mirrorPoint; y++)
topPixel.setColor(bottomPixel.getColor());
int mirrorPoint = (int) (getHeight() / 2);
Pixel topPixel = null;
Pixel bottomPixel = null;

b. From LLNode.java (another complete method)

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

c. From GUITreeInteractive.java

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

d. From GUITreeBordered.java

this.setVisible(true);
panel2.add(button2);
this.pack();
this.getContentPane().add(panel2,BorderLayout.SOUTH);
JButton button1 = new JButton("Make a sound");
JPanel panel2 = new JPanel();
panel2.add(button1);
JButton button2 = new JButton("Make a picture");

E. From SoundBranch.java
(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().
   **/


else
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=childSound.append(node.collect());
childSound = children.collect();
public Sound collect(){

(It's okay to rewrite this one so that it's better than the one in class!)

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



Draw the Object Structures


Draw the object structures (e.g., boxes and arrows) for the data structures resulting from these methods.

A. From SoundListTest.java

 public void setUp4(){
    FileChooser.setMediaPath("/Users/guzdial/cs1316/MediaSources/");
    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);
    root.repeatNext(one,4);

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

    s = new Sound(FileChooser.getMediaPath("clap-q.wav"));
    SoundElement three = new SoundElement(s);
    two.last().repeatNext(three,3);

    root.playFromMeOn();
  }


B. From SoundTreeExample.java
    public void setUp3() {
    FileChooser.setMediaPath("/Users/guzdial/cs1316/MediaSources/");
    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));
    branch1.addChild(sn);
    sn = new SoundNode(clink.append(snap).append(clave));
    branch1.addChild(sn);
    sn = new SoundNode(guzdial.append(is).append(is));
    branch1.addChild(sn);
    root.addChild(branch1);

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

    SoundBranch branch2 = new SoundBranch();
    sn = new SoundNode(clap.append(is).append(snap));
    branch2.addChild(sn); // Mark changed 5 April -- was branch1
    sn = new SoundNode(clink.append(snap).append(clave));
    branch2.addChild(sn); // Ditto
    sn = new SoundNode(chirp.append(is).append(is));
    branch2.addChild(sn); // Ditto*2

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

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

    root.playFromMeOn();
  }


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



What's My Data Structure?


We've talked about several data structures in this class: Arrays, matrices, 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. "I'm like my sister that you met early, but she's so one-dimensional, while twice as sophisticated, er, complex!"

D. "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 Sp2006: What's My Data Structure?



Explain the UML Part 2


Consider the below diagram. (Note: REMOVEDes with no arrows are "association" links.)

External Image

Answer the below questions:
A. A Transcript consists of a set of objects that store a Section of a Course taken and a grade earned. What class are those objects?

B. List all of the methods that a Student instance understands, and list all of the data fields that a Student instance contains.

C. How many Sections of a Course can exist?

D. How many Courses are associated with a given Section?

Questions, comments, answers at Midterm exam 2 review Sp2006: Explain the UML


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) {
    FileChooser.setMediaPath("D:/cs1316/mediasources/");

    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);
    treenode2.setNext(dognode2);

    Picture bg = new Picture(400,400);
    treenode.drawFromMeOn(bg);
    bg.show();

  }
}


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 Sp2006: 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 Sp2006: Java, Java, Java, says George


Let's be Discrete, or not


Answer the following questions about Simulations:

A. What's a queue and what do they have to do with simulations?

B. What's an example of a discrete event simulation? A continuous simulation?

C. Give me one example from a profession that you're interested in where it might be useful to build a simulation

Questions, comments, answers at Midterm exam 2 review Sp2006: Let's be Discrete, or not

Links to this Page