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

Midterm exam 2 review Sp2006: Unscramble the Code

Comments, Questions, Answers, Questions about Answers?
(Back to Midterm Exam 2 Review Sp2006)


I guess I'll try to unscramble one.....

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


Does this look right?

Looks good to me... Personally, E was giving me a headache, but I think I got it– How's this look:
public Sound collect(){
  Sound childSound;
  CollectableNode node;
  if(children!=null){
    childSound=children.collect();
  }else{
    childSound=new Sound(1);
  }
  node=(CollectableNode) this.getNext();
  if(this.getNext()!=null){
    childSound=childSound.append(node.collect());
  }
  return childSound;
}

It's kinda weird, seems like one line in out of place, but I think it still works...
~Jim

The reason why E is giving you a headache is that I figured out, by putting this on last year's exam, that there's a much better way to write the code. Several students figured it out last semester.
You can always check these, before the exam. They're in your java-source. Mark Guzdial

What is children in part E? It doesn't seem to be mentioned as a variable..

children is a variable in the branch, remember? Mark Guzdial



Link to this Page