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

Midterm exam 2 review Spring2007: Make a Scene

Back to Midterm Exam 2 Review-Spring 2007

Questions? Answers? Comments?


public class PSETest {
  public static void main(String [] args) {
    FileChooser.setMediaPath("D:/cs1316/mediasources/");

    Picture dog = new Picture(FileChooser.getMediaPath("dog-blue.jpg"));
    dog.scale(.25)
    PositionedSceneElement dognode = new PositionedSceneElement(dog);

    Picture house = new Picture(FileChooser.getMediaPath("house-blue.jpg"));
    PositionedSceneElement housenode = new PositionedSceneElement(house);
    PositionedSceneElement housenode2 = new PositionedSceneElement(house);
    PositionedSceneElement housenode3 = new PositionedSceneElement(house);

    Picture tree = new Picture(FileChooser.getMediaPath("tree-blue.jpg"));
    PositionedSceneElement treenode = new PositionedSceneElement(tree);
    PositionedSceneElement treenode2 = new PositionedSceneElement(tree);
    PositionedSceneElement treenode3 = new PositionedSceneElement(tree);

    Picture bg = new Picture(FileChooser.pickAFile("jungle.jpg"));

    dognode.setNext(housenode); housenode.setNext(housenode2); 
    housenode2.setNext(housenode3); 
    housenode3.setNext(treenode); 
    treenode.setNext(treenode2);
    treenode2.setNext(treenode3);

    treenode.drawFromMeOn(bg);
    bg.show();

  }
}


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.scale(0.25));
    Picture house = new Picture(FileChooser.getMediaPath("house.jpg"));
    PositionedSceneElement housenode = new PositionedSceneElement(house);
    PositionedSceneElement house2 = new PositionedSceneElement(house);
    PositionedSceneElement house3 = new PositionedSceneElement(house);
    Picture tree = new Picture(FileChooser.getMediaPath("tree-blue.jpg"));
    PositionedSceneElement treenode = new PositionedSceneElement(tree);
    PositionedSceneElement treenode2 = new PositionedSceneElement(tree);
    PositionedSceneElement treenode3 = new PositionedSceneElement(tree);
    dognode.setNext(housenode);      
    housenode.setNext(house2);
    house2.setNext(house3);
    house3.setNext(treenode);
    treenode.setNext(treenode2)
    treenode2.setNext(treenode3);

    Picture bg = new Picture(FileChooser.getMediaPath("jungle.jpg")););
    dognode.drawFromMeOn(bg);
    bg.show();

  }
}
Is that correct?

Other than the semicolon after the line: treenode.setNext(treenode2) it compiles and produces the desired output. Remember that you should be able to produce the code in dr. java and you're able to test these out there. Well done.

Brian O'Connor

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.scale(0.25));

    Picture tree = new Picture(FileChooser.getMediaPath("tree-blue.jpg"));
    PositionedSceneElement treenode = new PositionedSceneElement(tree);
   
    Picture house = new Picture(FileChooser.getMediaPath("house-blue.jpg"));
    PositionedSceneElement housenode = new PositionedSceneElement(house);

    dognode.repeatNext(treenode,3); dognode.repeatNextInserting(housenode,3);
    Picture jungle = new Picture(FileChooser.getMediaPath(“jungle.jpg”));
    dognode.drawFromMeOn(jungle);
    jungle.show();
  }
}
// that's gotta be right, right?

That worked for me, but for some reason I didn't have the methods repeatNext and repeatNextInserting in PositionedSceneElement.java. If for some reason you guys don't have these methods then they should look like:


public void repeatNext(PositionedSceneElement p, int num) {
this.next = p.copy();
for(int i=1; inum; i++) {
this.insertAfter(p.copy());
}
}
public void repeatNextInserting(PositionedSceneElement p, int num) {
for(int i=0; inum; i++) {
this.insertAfter(p.copy());
}
}

Brian O'Connor

what's up with the gangster-ness?



Link to this Page