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

Final Exam Review Fall2006

Below are questions like those we plan to ask on the Final Exam (Friday the 15th at 2:50 pm). The exam will consist of questions like these.

Please do try these questions! Post your answers, questions, comments, concerns, and criticisms on the pages for each question. Those comments, questions, etc. can also be about each others' answers! If someone posts an answer that you don't understand, ask about it! If you see a question here that you know the answer to, don't keep it to yourself – help your fellow students!

We will be reading your answers. Here are the ground rules for the interaction.
  1. If you don't post, neither will we. We will not be posting official solutions to these problems at all! If one of you gets it right, terrific!
  2. We will try to always point out if an answer is wrong. We won't always point out when the answer is right.
  3. We are glad to work with you toward the right answer. We will give hints, and I'm glad to respond to partial guesses.

True or False


It is easier to insert and remove data from an array.

A ticket sales line referred to as “first come, first serve” can be considered a stack – one of the data structures we discussed in 1316.

Methods push, pop, peek, and size are all part of the stack data structure.

Trees and Graphs both are arrays.

Questions, comments, answers at Final exam review Fall2006: True or False

Short answer


Explain modeling and how it applies to this course.

What is meant by a method being declared to be static?

Often we see references to variables that are in all caps. An example would be SOUTH in the BorderLayout class. What does this typically mean?

Explain the differences between continuous and discrete simulations. Give examples of both. What is the queue data structure used to represent in a simulation?


Questions, comments, answers at Final exam review Fall2006: Short answer

Understanding Java modifiers


For the following lines of code, explain how the bold words affect the method or variable:

public boolean compare(int a, int b){ …

private final sound = null;

public static void main(String[] args) { …


What are instance variable modifiers? REMOVEDst them.


Questions, comments, answers at Final exam review Fall2006: Understanding Java modifiers

Understanding UML

Answer the questions based on the following UML diagram. Note: the labels for the association between Flight and CrewMember are reversed.
Uploaded Image: image001.png
A. REMOVEDst all of the methods in an instance of Attendant.

B. How does a Pilot access all of the passengers on the flight?

C. REMOVEDst all of the classes that understand name.

D. REMOVEDst all of the instance variables in an instance of Flight.

E. By what names does a flight know all of its crew members?

F. How many crew members are there on every flight?

Questions, comments, answers at Final exam review Fall2006:Understanding UML

Understanding inheritance


Given the following code:

public class Superhero {
  public String name;
  public int strength;
  public Superhero() {
    name = “Batman”;
    strength = 10;
  }
  public void introduce() {
    System.out.print(“Hello.  I am “ + name + “.  And “);
    if(strength < 15) {
      System.out.println(“I am weak.”);
    } else {
      System.out.println(“I am strong.”);
    }
}


public class  NinjaTurtle extends Superhero {
  public NinjaTurtle(int i) {
    super();
    String[] turtles = {“Leonardo”, “Donatello”, “Raphael”, “Michaelangelo”};

    name = turtles[i];
    strength = 25;
  }
  public void introduce() {
    System.out.println(“I’m “ + name);
  }
}


What will the output of the following statements be?

> Superhero batman = new Superhero();
> Superhero leo = new NinjaTurtle(0);
> leo.introduce();
> batman.introduce();

When you create a method in a subclass that overrides a method from the superclass, how do you invoke the superclass method's behavior? What constraints are there for doing this in a constructur of a subclass?

Consider the following LLNode and DrawableNode classes:


abstract public class LLNode {

  /*The next branch/node/whatever to process*/
  public LLNode next;

  /*Constructor for LLNode just sets next to null*/
  public LLNode() {
    next = null;
  }

  /**
   *Methods to set and get next elements* @param nextOne next element in list
   */
  public void setNext(LLNode nextOne) {
    this.next = nextOne;
  }

  public LLNode getNext() {
    return this.next;
  }

  /*** Method to remove node from list, fixing links
   *appropriately* @param node element to remove from list.
   */
  public void remove(LLNode node) {
    /* assume you have working code here */
  }

  /*** Insert the input node after this node
   *@param node element to insert after this
   **/
  public void insertAfter(LLNode node) {
    /* assume you have working code here */
  }
} //end of LLNode class

public class DrawableNode {
  public DrawableNode next;

  /* Constructors */
  public DrawableNode() {
    next = null;
  }

  /* Methods */
  public void setNext(DrawableNode nextOne) {
    this.next = nextOne;
  }

  public Drawable getNext() {
    Return this.next;
  }

  public void remove(DrawableNode node) {
    /* Assume working code */

  public void insertAfter(DrawableNode node) {
    /* Assume working code */
  }
}// end of DrawableNode class


Rewrite the DrawableNode class to have it extend the LLNode class. You are to retain in the new version of DrawableNode only the code that is the essence of handling pictures, removing all functionality that is to be handled by LLNode.

Questions, comments, answers atFinal exam review Fall2006:Understanding inheritance

GUIs are trees


Look at the following code:
import java.awt.*; 
import javax.swing.*;

/** Simple GUI Tree Example
  * This is a GUI Tree Example designed to give you an idea
  * of what we want you to do on the exam. We realize that
  * there is not much material on this in the lecture slides, 
  * but a GUI Tree is very similar to the work you have done
  * with "Sound Trees" (i.e. SoundBranch, etc) 
  **/
public class SimpleGUITreeExample extends JPanel{
  
  public SimpleGUITreeExample(){
    /** Since our class extends JPanel, it itself (this) is a 
      * JPanel as well. So let's set the layout to be a 
      * BorderLayout
      **/
    this.setLayout(new BorderLayout());
    
    /** Let's start creating the panel to add into this
      */
    
    //panel1 is a JPanel with a BorderLayout
    JPanel panel1 = new JPanel();
    panel1.setLayout(new BorderLayout());
    
    //Here we create button1, button2, button3 which are all JButtons
    JButton button1 = new JButton("Button 1");
    JButton button2 = new JButton("Button 2");
    JButton button3 = new JButton("Button 3");
    
    //We add button1, button2, button3 to panel1
    panel1.add(button1, BorderLayout.NORTH);
    panel1.add(button2, BorderLayout.CENTER);
    panel1.add(button3, BorderLayout.SOUTH);
    
    //Add panel1 to this
    this.add(panel1, BorderLayout.NORTH);
    
    //panel2 is a JPanel with a FlowLayout
    JPanel panel2 = new JPanel();
    panel2.setLayout(new FlowLayout());
    
    //We create button4 and button5 which are JButtons
    JButton button4 = new JButton("Button 4");
    JButton button5 = new JButton("Button 5");
    
    //Add button4 and button5 to panel2
    panel2.add (button4);
    panel2.add (button5);
    
    //Add panel2 to this
    this.add(panel2, BorderLayout.SOUTH);
    
  }
    public static void main (String[] args){
    JFrame frame = new JFrame ("Simple GUI Tree Example");
    frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    
    SimpleGUITreeExample tree = new SimpleGUITreeExample();
    frame.getContentPane().add(tree);
    frame.pack();
    frame.setVisible(true);
  }  
}

Here is the tree structure for SimpleGUITreeExample
Uploaded Image: SimpleGUITreeExampleTreeStructure.jpg


You are given the following class:
import java.awt.*;
import javax.swing.*;

public class ExampleGUI extends JPanel {

  public ExampleGUI() {

    JPanel buttonPanel = new JPanel();
    JPanel contentPanel = new JPanel();
    contentPanel.setLayout(new BorderLayout());
    JPanel toSendTextPanel = new JPanel();
    toSendTextPanel.setLayout(new BorderLayout());
    
    JLabel receivedTextLabel = new JLabel("Received Messages");
    JLabel toSendTextLabel = new JLabel("Text to Send");
    JTextArea receivedText = new JTextArea("Jess: Hey Dawn, are you TAing next semester?\n"+
                                           "Dawn: Nope. I'll be in sunny California getting a tan.\n"+
                                           "Jess: Okay, but you have to get rid of that ugly farmer's tan.", 10, 10);
    JTextArea toSendText = new JTextArea("Start typing here", 5, 10);
 
    JButton warn = new JButton("Warn");
    JButton chat = new JButton("Chat");
    JButton send = new JButton("Send");
    
    this.setLayout(new BorderLayout());

    toSendTextPanel.add(toSendTextLabel, BorderLayout.NORTH);
    toSendTextPanel.add(toSendText, BorderLayout.SOUTH);
    
    buttonPanel.add(warn);
    buttonPanel.add(chat);
    buttonPanel.add(send);

    contentPanel.add(receivedTextLabel, BorderLayout.NORTH);
    contentPanel.add(receivedText, BorderLayout.CENTER);
    contentPanel.add(toSendTextPanel, BorderLayout.SOUTH);

    add(contentPanel, BorderLayout.CENTER);
    add(buttonPanel, BorderLayout.SOUTH);
  }

  public static void main(String[] args) {
    JFrame frame = new JFrame("IM");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    ExampleGUI ex_gui = new ExampleGUI();
    frame.getContentPane().add(ex_gui);
    frame.pack();
    frame.setVisible(true);
  }
}


Draw the resulting GUI.



How would you represent the GUI structure as a tree?


Questions, comments, answers atFinal exam review Fall2006:GUIs are trees

Writing methods on the Picture class

The following is the clearBlue() method of the class Picture.
/*** Method to clear the blue from the picture (set
 *the blue to 0 for all pixels*/
public void clearBlue()
{
  Pixel[] pixels = this.getPixels();
  Pixel pixel = null;
  int index = 0;

  while(index < pixels.length)
  {
    pixel = pixels[index];
    pixel.setBlue(0);
    index++;
  }
}


Write a method to draw vertical stripes (leaving a gap for the original picture between every stripe) down the picture. Have every-other stripe be red, and the others be green.

Public void vertical_stripes()
{

}



Questions, comments, answers at Final exam review Fall2006:Writing methods on the Picture class

Insertion sort

Below is the insertion sort() method from EventQueue:
Public void sort() {

  SimEvent considered = null;
  SimEvent compareEvent = null; //Just for use in the loop

  /*  Small index we’re comparing to */
  int compare;

  for(int position = 1;position < elements.size();position++){
    considered = (SimEvent) elements.get(position);
    
    compare = position;

    compareEvent = (SimEvent) elements.get(compare-1);
    while(compareEvent.getTime() > considered.getTime()) {
      elements.set(compare, elements.get(compare-1));
      compare = compare – 1;
      // If we get to the end of the array, stop
      if(compare <= 0) {break;}
      // else we get ready for the next time through the loop
      else { compareEvent = (SimEvent)elements.get(compare-1);}
    }

    elements.set(compare, considered);
  }// for all positions 1 to the end
}// end sort()


  1. Why do we need two loops for this sorting algorithm? Explain the purpose of each.
  2. How would we go about reversing the sort (lets say we wanted the most time consuming element to happen first)?
  3. Why did we start out with the variable position being set to 1 instead of 0?
  4. At the point in the code where considered is defined in the for loop, what do we know is true about the times of the SimEvents in the linked list that occur before the newly defined considered SimEvent?

Questions, comments, answers at Final exam review Fall2006:Insertion sort

Writing linked list methods


Below is the remove() method taken from the class LLNode
public void remove(LLNode node) {
  if(node == this) {
    System.out.println(“I can’t remove the first node”);
    return;
  }
  
  LLNode current = this;
  while(current.getNext() != null)
  {
    if(current.getNext() == node) {
      current.setNext(node.getNext());
      node.setNext(null);
      return (null);
    }
    current = current.getNext();
  }
}


Write a method that will take in a number and delete that node from the list (remember to check if the number is longer than your list).

For example, if our list looks like A -> B -> C -> D -> null and we call the method A.remove(3), our list should look like A -> B -> D -> null. (we start our indexing at 1).

public void remove(int index) {


}

Questions, comments, answers at Final exam review Fall2006:Writing linked list methods

Abstract Data Types


  1. What operations can be performed on the stack abstract data type?
  2. How is a stack different from a queue?

Questions, comments, answers at Final exam review Fall2006:Abstract Data Types


Simulations


Know what the difference is between a continuous simulation and a discrete event simulation.

We defined a collection of classes in lecture to support the development of simulations. What data structures did we use and why? How has this eased the development of different simulations?

We used random number generators to help control the execution of continuous and discrete event simulations. How were they used and why? What kinds of distributions did we discuss and how are they distinguished?

You are going on to a career in computational media or industrial engineering. Give a concrete example of how a simulation would be useful in your potential new career.

Questions, comments, answers at Final exam review Fall2006:Simulations

Links to this Page