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

Pre-Quiz2-Summer 2007

Summer 2007 Pre-Quiz pdf version

1. Consider the following code
public abstract class Animal {

  public abstract boolean isExtinct();
  public String toString() { return "An animal";}
  
  }
}

public class Dinosaur extends Animal {
  
  public static final Dinosaur BARNEY = new Dinosaur();

  public boolean isExtinct() {
    return true;
  }
  
}


(a) Which of the following declarations are valid? Check all that apply. [4 points]
(i) Animal dino = new Dinosaur();
(ii) Dinosaur dino = new Dinosaur();
(iii) Animal anne = new Animal();
(iv) Dinosaur anne = new Animal();

(b) Given a Dinosaur dave, what do the following commands return when typed in the Dr. Java interactions pane? [3 points]
(i) dave.toString()
(ii) dave.isExtinct()
(iii) dave


(c) How would you refer to BARNEY in the following? [1 point]
_________________________.toString()


2. Suppose we have a linked list of books in a library and the books are defined as follows:
public class BookElement {
  private String bookDetails = "";
  private BookElement next = null;

  public String getDetails() {return this.bookDetails;}
  public BookElement getNext() {return this.next;}
  public void setDetails(String details) {this.bookDetails = details;}
  public void setNext(BookElement be) {this.next = be;}

}


Write a method length() that returns the length of the list that starts at this by filling in the code template below. [10 points]
public int length() {

  // Hint: Initialize number here.
  // Also, you need a current element, starting at this.



  // Hint: Then comes the standard while loop for the traversal

  while (_________________________________________) {

    // Hint: do something inside the loop that helps you count.



    // Hint: do something so that the loop doesn't repeat for ever.
  


  }
  return number
}

3. A model is not the same as reality, but always simplifies some aspects of reality. JMusic is a powerful way to model music computationally, but it is still a model. Give ONE way in which JMusic seems to simplify music. [2 points]





Questions? Answers? Post them on Pre-Quiz 2-Summer 2007 Questions

Links to this Page