©2006 Felleisen, Proulx, et. al.

2  Self-Referential Data; Designing Methods -- Part 1

We continue with the the theme of the photo images. Our collections of images surely contains more than one picture. We will first define a list of images.

Once we have the data that represents our pictures, we would like to be able to ask questions about the data. To do so, we design methods in the classes that represent our data.

2.1  Self-Referential Data

  1. The HtDP data definition for a list of photos is:

    ;; A ListOfPhotos is one of
    ;; --- empty
    ;; --- (cons Photo ListOfPhotos)
    

    Design the Java classes to represent a list of Photos. Remember to make examples of data.

    Note: This is the last time we will remind you to make examples of data.

  2. The textbook uses classes that represent geometric shapes to illustrate the design of classes. Define Java classes that correspond to the following class diagram.

                            +-------+                            
                            | Shape |<--------------------------+
                            +-------+                           |
                            +-------+                           |
                                |                               |
                               / \                              |
                               ---                              |
                                |                               |
             ---------------------------------------            |
             |                  |                  |            |
      +-------------+    +-------------+    +--------------+    |
      | Square      |    | Circle      |    | Combo        |    |
      +-------------+    +-------------+    +--------------+    |
    +-| Posn nw     |  +-| Posn center |    | Shape top    |----+
    | | int size    |  | | int radius  |    | Shape bottom |----+
    | | Color color |  | | Color color |    +--------------+ 
    | +-------------+  | +-------------+                     
    +----+ +-----------+
         | |
         v v
      +-------+
      | Posn  |
      +-------+
      | int x |
      | int y |
      +-------+
    
      

Learn to use the homework submission server. The TAs will give you the instructions.

2.2  Methods for Simple Classes and Classes with Containment

For this series of exercises use the classes from Lab 1 that represented photo images and included the date and time information.

Below is an example of the design of a method that computes the number of pixels in a photo image:

  1. Design the method that determines how long it will take to download this image, if we know the number of bytes we can download in one second.

  2. Design the method that determines whether this picture was taken before another picture.

    Remember: One task, one method. Make each class responsible for its data.

  3. In the class ClockTime design the method that advances the time by the given number of minutes. Use helper methods as needed.

Time for the quiz.

2.3  Methods for Unions

For this part use the data for camera shots (photos or videos) from the previous lab.

  1. Design the method that determines how long it will take to download this shot, if we know the number of bytes we can download in one second.

  2. Design the method that determines whether this shot will download faster than another one at the given download speed.

Save all your work -- the next lab will build on the work you have done here!

If you have some time left, work on the Etudes part of the homework.

Last modified: Monday, January 22nd, 2007 4:01:20pm