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

Pre-Quiz2 - Fall 2006

Q1. Who's your grading TA? (Please circle your answer)
Dawn 	 Joel 	  Mark 	   Brian    REMOVEDng-Yen 	  Richard

Q2. Answer the following questions by circling either True or False.
            ________True________False___________


            ________True________False___________

Q3. What is a static method and why would you ever want one?



Q4. The following is the implementation of the weave() method defined on the class SongNode:

  /**
   *Weave the input phrase count times every skipAmount nodes* @param nextOne node to be copied into the list
   *@param count how many times to copy
   * @param skipAmount how many nodes to skip per weave
   /
  public void weave(SongNode nextOne, int count, int skipAmount) 
  {
    SongNode current = this; // Start from here
    SongNode copy; // Where we keep the one to be weaved in
    SongNode oldNext; // Need this to insert properly
    int skipped; // Number skipped currently
    
    for (int i=1; i <= count; i++)
    {
      copy = nextOne.copyNode(); // Make a copy
      
      //Skip skipAmount nodes
      skipped = 1;
      while ((current.next() != null) &amp; (skipped < skipAmount))
      {
        current = current.next();
        skipped++;
      };
      
      //if (current.next() == null) // Did we actually get to the end early?
        //break; // Leave the loop
      
      oldNext = current.next(); // Save its next
      current.insertAfter(copy); // Insert the copy after this one
      current = oldNext; // Continue on with the rest
      if (current == null) // Did we actually get to the end early?
        break; // Leave the loop
    }
}


The following commands in DrJava:
Welcome to DrJava.
> SongNode node1 = new SongNode();
> node1.setPhrase(SongPhrase.riff1());
> SongNode node2 = new SongNode();
> node2.setPhrase(SongPhrase.riff2());
> node1.repeatNext(node2,3);

Result in a linked list that can be drawn as
Uploaded Image: list.jpg

Draw the result of the following commands in DrJava:
Welcome to DrJava.
> SongNode node1 = new SongNode();
> node1.setPhrase(SongPhrase.riff1());
> SongNode node2 = new SongNode();
> node2.setPhrase(SongPhrase.riff2());
> SongNode node3 = new SongNode();
> node3.setPhrase(SongPhrase.riff3());
> node1.repeatNext(node3,5);
> node1.insertAfter(node2);
> node1.weave(node2,1,4);


Comments, questions, and answers!


Our TA said that a subclass canNOT override any method in its super class, is this true?


yeah, that's true...Dawn just sent out the following email to everyone in her section:

The answer to question 2B is false, because apparently we can't
overwrite private (or static ones I think) methods in the parent class.


ok



Link to this Page