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

Midterm Exam 2 Review Fall2005

Below are questions like those I plan to ask on Midterm #2 (November 18). 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.



Explore the UML


Answer the Questions below about the UML diagram here:
Uploaded Image: midtermexam2-uml.jpg

A. Instances of which classes have a field (instance variable) named address?

B. Do HourlyEmployee instance have offices?

C. By what name do instances of the class Office know their Building instances?

D. List all the fields (instance variables) of a SalariedEmployee.

E. List all the classes whose instances understand the method fire().

Questions, comments, answers at Midterm exam 2 review Fall2005: Explore the UML


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");

Questions, comments, answers at Midterm exam 2 review Fall2005: 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 Fall2005: 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 Fall2005: 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 Fall2005: 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 Fall2005: 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. What's a Stream and what would I do with one?

D. "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 Fall2005: Java, Java, Java, says George


Tweak the Politics


Here's the act() method from PoliticalAgent

  /**
   * How a PoliticalAgent acts
   **/
  public void act()
  {
    this.stuckness--;
    
    // What are the number of blues and red near me?
    int numBlue = countInRange(30,blueParty);
    int numRed = countInRange(30,redParty);
    /*System.out.println("I am "+politics+" and near me are red:"
                         +numRed+" and blue:"+numBlue);*/
    if (politics==Color.red){
      // If I'm red, and there are more blue than red near me, convert
      if ((numBlue > numRed) && (this.stuckness <= 0)){
        setPolitics(Color.blue);}
    }
    if (politics==Color.blue){
      // If I'm blue, and there are more red than blue near me, convert
      if ((numRed > numBlue) && (this.stuckness <= 0)) {
      setPolitics(Color.red);}
    }

    // Run the normal act() -- wander aimlessly
    super.act();
    
    // But don't let them wander too far!
    // Let them mix only in the middle
    if (politics==Color.red) {
      if (this.getXPos() > 400) { // Did I go too far right?
        this.moveTo(200,this.getYPos());}
    }
     if (politics==Color.blue) {
      if (this.getXPos() < 200) { // Did I go too far left?
        this.moveTo(400,this.getYPos());}
     }
   
  }




Questions, comments, answers at Midterm exam 2 review Fall2005: Tweak the Politics


Links to this Page