Assignment 1

CS 146
due September 20, 2001
100 points, plus 10 points extra credit

Define classes Image and ImageCollection that respectively represent a data type for images and a collection class for images. The ImageCollection class should implement the Collection interface. Test with the main function in the file A1.java, obtainable from the class web site.

An image consists of an n by n array of booleans, where the values of TRUE and FALSE correspond to pixels of two different colors. You may choose to have other fields in your Image class, and other methods besides the ones specified below.

Both classes should support a method draw. For full credit (including the extra credit), the draw method for Images should draw a representation to a Java Frame (ideally a JFrame). For a 20-point penalty (10 regular points and 10 points of extra credit), you may print a representation of the image to System.out, using two different characters to represent the two possible pixel values. If you do the former, you needn't turn in hard copies of the drawn images. If you do the latter, the drawn images should appear in the hard copy of your results. In either case, you may pass the method any appropriate parameters.

The draw method for ImageCollection should simply iterate over the collection, arranging to pass the draw message to each image.

You should also have an image constructor that constructs a random image given a value for n and a Random object. This constructor should get a sequence of booleans from the object and use them to build the image in row-major order.

For the Image class, you should also define methods to override equals and hashCode, using the technique of hash signatures. You needn't override the clone or toString methods for either of your classes. Note that the hashCode method for the Object class is public; this property is used in the main function.

The ImageCollection class should also support a method addImage that will take an Image as an argument and add it to the collection.

Please use the hash function that returns values from 0 through 7, whose three bits are set to 1, if, from high order to low, the following values are true: