import geometry.*; import java.util.*; class FigureDemo { /* Figure largest(LinkedList
fs) { } Figure largest(ArrayList
fs) { } */ static Figure largest(List
fs) { if (fs.size() > 0) { Figure max = fs.get(0); for (Figure f : fs) { if (max.compareTo(f) < 0) max = f; } return max; } else return null; } static Figure largestIterator(List
fs) { if (fs.size() > 0) { Iterator
it = fs.iterator(); Figure max = it.next(); while (it.hasNext()) { Figure f = it.next(); if (max.compareTo(f) < 0) max = f; } return max; } else return null; } public static void main(String[] args) { Figure f1 = new Square(2, 0, 1); Figure f2 = new Circle(4, 5, 3); LinkedList
fs = new LinkedList<>(); fs.add(f1); fs.add(f2); fs.add(new Circle(0,0,6)); System.out.println(largest(fs).show()); ArrayList
fsArrayL = new ArrayList<>(); fsArrayL.add(f1); fsArrayL.add(f2); fsArrayL.add(new Circle(0,0,6)); System.out.println(largest(fsArrayL).show()); List
singleton = new ArrayList<>(); singleton.add(f1); System.out.println(largest(singleton).show()); } }