Other 2004 FR Questions FR other years Be Prepared Home
AB-1
Part (a)
public interface LibraryItem
{
  String getId();
  String getHolder();
  void setHolder(String holder);
}

Part (b)
public class LibraryBook extends Book
    implements LibraryItem
{
  private final String theId; 1
  private String theHolder;

  public LibraryBook(String id, String author, String title)
  {
    super(author, title);
    theId = id;
    theHolder = null; 2
  }

  public String getId() { return theId; }
  public String getHolder() {return theHolder; }
  public void setHolder(String holder) { theHolder = holder; }
}
Notes:
  1. final is optional.

  2. This statement is optional: null is the default for fields that are references to objects.

Part (c)

Your data representation (Circle one) How data is organized

  ArrayList      LinkedList
  HashMap        TreeMap
  HashSet        TreeSet
HashMap. 1, 2  If item is a LibraryItem,
item's ID is the key, and item is the
associated value.

Operations Expected Big-Oh efficiency
add O(1)
checkoutO(1)
getHolder 3 O(1)

Notes:

  1. The trick is to pick an appropriate data structure with predictable performance.  Implementation efficiency does not matter.

  2. You could pick TreeMap as well.  Then the efficiency of all three methods would be O(log n).

  3. checkout and getHolder have the same big-O -- it is determined by the big-O for finding the item.

Other 2004 FR Questions | Back to Contents

Copyright © 2004 by Skylight Publishing
support@skylit.com