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

PracticeFinalSummer07

UML Diagram [pdf]

For the following boxes, please draw the indicted relationships (1-3). Remember to include cardinality, reference variables and arrows.
UMLDiagramPicture.JPG
1. A Manager knows how to delegate responsibilities to his many Employees. Employees know how to do the work assigned to them. Both Managers and Employees have names. Managers know who their Employees are and Employees know their Manager.

2. An Airport has many Airplanes. Airports have a name and location and know how to delay Airplanes. Airplanes have an airline and know how to take off and land. Airports know their Airplanes and Airplanes know their Airport.

3. A NinjaTurtle is a SuperHero. Michelangelo is a NinjaTurtle. A SuperHero knows how to fight crime. A NinjaTurtle knows how to eat pizza and knows its weapon. Only Michelangelo knows how to get pizza.

Ask questions at Questions-PracticeFinalSummer07-UMLDiagram.

Stack and Queue Methods [pdf]

A. STACK
1. For your stack, insertion occurs at the ____________ (first/last).

2. For your stack, removal occurs at the ____________ (first/last).

3. Implement the following methods for a stack according to your specifications for insertion and removal (Assume the linkedlist of elements in the stack is called elements and is already available to you):
     a. public boolean isEmpty()




     b. public Object pop()




     c. public void push(Object item)






B. QUEUE
1. For your queue, insertion occurs at the ____________ (first/last).

2. For your queue, removal occurs at the ____________ (first/last).

3. Implement the following methods for a queue according to your specifications for insertion and removal (Assume the linkedlist of elements in the queue is called elements and is already available to you):
     a. public boolean isEmpty()




     b. public Object pop()




     c. public void push(Object item)




Ask questions at Questions-PracticeFinalSummer07-StackAndQueueMethods.

REMOVEDked List Methods [pdf]


A. TRACING THE CODE
Consider the following code:
public void remove(PositionedSceneElement node){
   //Question 1 
   if (node==this){
      System.out.println("I can't remove the first node from the list.");
      return;
    } 
    //Question 2
    PositionedSceneElement current = this;
    //Question 3
    while (current.getNext() != null){
     //Question 4 
     if (current.getNext() == node){
        current.setNext(node.getNext());
        node.setNext(null);
        return;
      }
      //Question 5
      current = current.getNext();
    }
  }

1. What are the requirements to enter the if-statement? What occurs in the if-statement? Why is this if-statement even necessary?

2. What is occurring in the line directly below the comment? Why is this necessary?

3. What are the conditions to enter the while-loop and under what conditions will the while-loop exit?

4. What are the requirements to enter the if-statement? What occurs in the if-statement?

5. What is occurring in the line directly below the comment? Why is this necessary?


B. WRITING A METHOD
Consider the following code:
public class Element {
  private Element next;
  public Element getNext() {return this.next;}
  public void setNext(Element next) {this.next = next;}
    
  public int length() {return 0;}

  public static void main(String[]args){
    Element node1 = new Element();
    Element node2 = new Element();
    Element node3 = new Element();
    Element node4 = new Element();
    node1.setNext(node2);
    node2.setNext(node3);
    node3.setNext(node4);
    node4.setNext(node1);
    System.out.println(node1.length());
  }
}
Rewrite the length() method so that when called it will print out the correct number of elements in the list. Remember that you do not know how many elements will be in the list so you cannot use a for-loop. You also cannot alter the linked list structure in any way.

public int length()


Ask questions at Student730.


Picture Methods [pdf]

Consider the following code:
public void grayscale(){
    Pixel pixel = null;
    int intensity = 0;
    Pixel[] pixels = this.getPixels();
  
    for (int i = 0; i < pixels.length; i++){
      pixel = pixels[i];
      intensity = (int) ((pixel.getRed() + pixel.getGreen() + 
                     pixel.getBlue()) / 3);
      pixel.setColor(new Color(intensity,intensity,intensity));
      
    }
  }
Write a Picture class method called public static int countThatColor(Picture picture, Color color, int range) that counts all the colors in an inputted picture that fall within a range of the inputted color. Also write a main method that will test your countThatColor method.

public static int countThatColor(Picture picture, Color color, int range)



Ask questions at Questions-PracticeFinalSummer07-PictureMethods.



Links to this Page