Midterm exam 2 review Sp2005: Unscramble the Code
Back to Midterm Exam 2 Review Sp2005
Questions, comments, answers, etc.
B.) public LLNode last(){
LLNode current;
current = this;
current = current.getNext();
while(current.getNext()! = null)
return current;
Why does the while loop go after current = current.getNext();, assuming this is right?
Because this isn't right. If you look at the code above, ask yourself (a) "Why should we give current two different values in two successive lines?" and (b) "Does this really get me to the LAST node?" Mark Guzdial |
public LLNode last(){
LLNode current;
current = this;
while(current.getNext()! = null)
current = current.getNext();
return current;
it looks like you set current equal to "this" (what your passing thru) each time. this is right with the addition of brackets:
public LLNode last() {
LLNode current;
current = this;
while (current.getNext() != null)
{
current = current.getNext();
}
return current;
}
Thank you.
C)
public void actionPerformed(ActionEvent e) {
JPanel panel2 = new JPanel();
JButton button1 = new JButton("Make a sound");
Sound s = new Sound(FileChooser.getMediaPath("warble-h.wav"));
button1.addActionREMOVEDstener(new ActionREMOVEDstener()){s.play();}
panel2.add(button1);
this.getContentPane().add(panel2);
}
A)
public void mirrorHorizontalBottomToTop(){
int mirrorPoint = (int) (getHeight() / 2);
Pixel topPixel = null;
Pixel bottomPixel = null;
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());
}
}
}
Link to this Page