5. 15 points

// For convenience, define a static method that squares its integer argument

static void square(MutableInteger i)
  {
  int value = i.getValue();
  i.setValue(value*value);
  }


// Get an Iterator from the list and use it to traverse the list, 
// squaring each element.

Iterator it = L.getIterator();

while( it.hasNext() )
  {
  square((MutableInteger)it.next());
  }

// Since the Iterator returns an Object, casting is need it before it
// can be passed to square.