import java.util.ArrayList; public class ListOfPictures { public static void main(String[] args) { ArrayList<Picture> gallery = new ArrayList<Picture>(); gallery.add(new Picture("degas1.jpg")); gallery.add(new Picture("gaugin1.jpg")); gallery.add(new Picture("monet1.jpg")); gallery.add(new Picture("monet2.jpg")); gallery.add(new Picture("renoir1.jpg")); // Your code here int sum = 0; for (Picture pic: gallery) { sum = sum + pic.getWidth(); } System.out.println("Sum of widths: " + sum); } }
sort
largest = inital element
for all other elements
if measure(element) > measuer(largest)
largest = element
import java.util.ArrayList; public class ListOfPictures { public static void main(String[] args) { ArrayList<Picture> gallery = new ArrayList<Picture>(); gallery.add(new Picture("degas1.jpg")); gallery.add(new Picture("guigou1.jpg")); gallery.add(new Picture("gaugin1.jpg")); gallery.add(new Picture("monet1.jpg")); gallery.add(new Picture("seurat1.jpg")); // Your code here Picture tallest = gallery.get(0); for (Picture element: gallery) { if (element.getHeight() > tallest.getHeight()) { tallest = element; } } System.out.println("Tallest height: " + tallest.getHeight()); tallest.draw(); } }