// FigureDisplayer.java // A solution to CS 10, assignment 4, part 3, Fall 2008 // cmc, updated 11/1/08 import java.util.ArrayList; import java.util.Random; import java.util.Collections; /** Displays a user-specified number of printed rectangles and/or triangles, randomly selected with randomly-generated features to System.out. The user can specify this number by the first command line argument - the default number is 5 if there is no argument. The user can also specify a random integer seed as the second command line argument. */ public class FigureDisplayer { private static final int DEFAULT_NUMBER = 5, MIN_CODE = 33, MAX_CODE = 126, // range of printable ascii codes MAX_OFFSET = 50, MAX_WIDTH = 20, MAX_HEIGHT = 10; public static void main(String args[]) { // set number of figures by command line argument if there is one int n = DEFAULT_NUMBER; if (args.length > 0) // might throw a NumberFormatException here n = Integer.parseInt(args[0]); // create random generator, using seed by second argument if it exists Random generator; if (args.length < 2) generator = new Random(); else { long seed = Long.parseLong(args[1]); // above line also might throw NumberFormatException generator = new Random(seed); } // create list of n figure printer objects with random properties ArrayList list = new ArrayList(); for (int i=0; i