
Consider this call:
JOptionPane.showMessageDialog(. . ., new MarsIcon(50));
Draw a sequence diagram.
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) };
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());
