CS 151

Cover page image

Cay S. Horstmann

Lecture 8

Sequence Diagram Practice 1

Consider this call:

JOptionPane.showMessageDialog(. . ., new MarsIcon(50));

Draw a sequence diagram.

Sequence Diagram Practice 2

Consider this method:

public static Comparable largest(Comparable[] values)
{
   Comparable result = null;
   for (int i = 0; i < values.length - 1; i++)
      if (i == 0 || result.compareTo(values[i]) < 0)
         result = values[i];
   return result;
}

and this call:

largest(countries);

where countries is defined as

Country[] countries = new Country[] {
   new Country("Uruguay", 176220),
   new Country("Thailand", 514000),
   new Country("Belgium", 30510) };

Sequence Diagram Practice 3

Repeat with this method

public static T <T> largest(T[] values, Comparator<T> comp)
{
   T result = null;
   for (int i = 0; i < values.length - 1; i++)
      if (i == 0 || comp.compare(result, values[i]) < 0)
         result = values[i];
   return result;
}

and this call:

largest(countries, new CountryComparatorByName());

Discussion