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

PreQuiz 2-Fall 2005

Assuming that PositionedSceneElement has the methods copy() and last(), trace the below code:

public class DrawAScene {
  public static void main(String [] args){
    FileChooser.setMediaPath("D:/cs1316/mediasources/");
    Picture p = new Picture(FileChooser.getMediaPath("swan.jpg"));
    PositionedSceneElement node1 = new PositionedSceneElement(p.scale(0.15));
    p = new Picture(FileChooser.getMediaPath("turtle.jpg"));
    PositionedSceneElement node2 = new PositionedSceneElement(p.scale(0.25));
    PositionedSceneElement node3 = new PositionedSceneElement(p.scale(0.25).flip());
    
    node1.setNext(node2.copy());
    node1.setNext(node3.copy());
    node1.getNext().setNext(node2.copy());
    for (int i=0; i<3; i++)
    {node1.getNext().getNext().last().insertAfter(node1.copy());}
    for (int i=0; i<4; i++)
    {node1.getNext().insertAfter(node2.copy());}
    
    Picture bg=new Picture(800,400);
    node1.drawFromMeOn(bg);
    bg.show();
  }
}


  1. What picture will be shown at the end? Sketch out the result.
  2. Draw a diagram of the nodes in the final linked list connected to node1 in this example.

Answers? Questions? Comments? Requests?


1. swan, i can't draw that here. but it looks like a scaled down swan picture from mediasources folder

2. n1 > n3 > n2 >n2 >n2 >n2 >n2 > n1 > n1 > n1

Removed at KS request

I didn't mean the last node, in "what will be shown at the end." I meant, "Tell me what's shown." Every picture. Mark Guzdial

oh, swan, normal turtle, flipped turtle 5 times then three swans

You rock! Mark Guzdial



Link to this Page