| 
                        
                           
  | 
                     
| Why is it so common to use a color model in which red, green and blue are the primary colors? | 
| 
                            | 
                     
| 
                            
                                | 
                     
| Define the term "translation" (as it relates to affine transforms). | 
| 
                            | 
                     
| 
                            
                                | 
                     
| What is a "convex shape"? | 
| 
                            | 
                     
| 
                            
                                | 
                     
| Illustrate a mitred join. | 
| 
                            | 
                     
| 
                            
                                | 
                     
| Provide an example of a ligature. | 
| 
                            | 
                     
| 
                            
                                | 
                     
JMUmble.  In this
    system, arriving messages are handled by a PostOffice
    object. Depending on how the system is configured at runtime, one or
    more objects might need to know when a message arrives. I have
    currently implemented several such classes:
    ScreenFlasher (which makes the entire screen flash --
    you always know when a message has arrived),
    PopularityTimer (which starts a clock that show the
    amount of time since the most recent message arrived), and
    Mumbler (which uses speech generation to read the name
    of the person that sent the message -- this is where the system got
    its name).  Use the observer pattern to develop a class model of
    this system (in UML). You do not need to include the attributes of
    each class, only the operations/methods. Include comments that
    describe each operation/method.  
    
            GateListenerDatabase class so that it uses
    type-safe collections (and is, itself, type-safe).
    
import java.util.*;
/**
 * A database of GateListenerRecord objects
 *
 */
public class GateListenerDatabase
{
    private HashMap              db;
    /**
     * Construct a new GateListenerDatabase
     */
    public GateListenerDatabase()
    {
	db = new HashMap();
    }
    /**
     * Add a GateListenerRecord to the database
     *
     * @param glr  The record to add
     * @return     true if successful and false otherwise
     */ 
    public boolean add(GateListenerRecord glr)
    {
	boolean            added;
	GateListenerRecord old;
	String             key;
	added = false;
	key = glr.getHost()+":"+glr.getPort();
	old = (GateListenerRecord)(db.get(key));
	if (old != null)
        {
	    added = false;
        }
	else 
        {
	    added = true;
	    db.put(key, glr);
	}
	return added;
    }
    /**
     * Drop a GateListenerRecord from the database
     *
     * @param glr  The record to drop
     * @return     true if successful and false otherwise
     */
    public boolean drop(GateListenerRecord glr)
    {
	boolean   dropped;
	Object    old;
	String    key;
	key = glr.getHost()+":"+glr.getPort();
	old = db.remove(key);
	dropped = true;
	if (old == null) dropped = false;
	return dropped;
    }
    /**
     * Returns an Iterator containing all of the GateListenerRecord 
     * Objects in the database
     *
     * @return  The Iterator of records
     */
    public Iterator getAll()
    {
        // This must be changed!
	return null;
    }
}
    
               
            Map object (e.g., a HashMap)
    can contain only one value for each key.  Hence, in order to
    keep a mapping of, say, students to grades, one has to be creative.
    One approach is to create
    a ManyValuedMap class that does not provide all of the
    functionality or a Map but delegates to an object
    that implements Map.  For example:
    
import java.util.*;
public class ManyValuedMap<K,V>
{
    private HashMap<K,ArrayList<V>>       delegate;
    public ManyValuedMap()
    {
        delegate = new HashMap<K,ArrayList<V>>();
    }
    // Returns all of the values associated with a key (or null)
    public ArrayList<V> get(K key)
    
    // Adds the value to the ArrayList associated with the given key
    public V put(K key, V value)
    // Removes the value from the ArrayList associated with the given key
    public V remove(K key)
}
    
               Implement this class.
ManyValuedMap
    above, one could extend the HashMap class as follows:
    
import java.util.*;
public class ManyValuedMap<K,V> extends HashMap<K,V>
{
    // Searches through all of the values in all of the keys
    public boolean containsValue(Object value)
    // Returns the first value for this key
    public V get(Object key)
    // Returns all of the values associated with a key (or null)
    public Iterator<V> getValues(K key)
    
    // Adds the value to the ArrayList associated with the given key
    public V put(K key, V value)
    // Throws UnsupportedOperationException
    public void putAll(Map<? extends K,? extends V> m) 
    
    // Removes the value from the ArrayList associated with the given key
    public V remove(Object key)
    // Returns a Collection of all of the values associated with all keys
    public Collection<V> values()
}
    
               Implement this class.
HashMap class as above,
    one could decorate a Map as follows:
    
import java.util.*;
public class ManyValuedMap<K,V> implements Map<K,V>
{
    private  Map<K,ArrayList<V>>       decorated;
    public ManyValuedMap(Map<K,ArrayList<V>> decorated)
    {
        this.decorated = decorated;
    }
    // All of the methods required in the Map interface should
    // delegate to decorated as needed
    // Returns all of the values associated with a key (or null)
    public Iterator<V> getValues(K key)
    {
       Collection<V>    values;
       
       values = decorated.get(key);
       
       if (values != null) return values.iterator();
       else                return null;       
    }
}
    
               Implement this class.
paint method:
      
      public void paint(Graphics g)
      {
        g.setColor(Color.black);
        g.fillRect(50,50,400,400);
        g.setXORMode(Color.white);
        g.fillRect(25,75,200,100);
      }
      
               
    Carefully illustrate, on the grid below, what would be drawn 
    by this paint() method if it were called.
    
               RectangleCanvas:
      
      public class RectangleCanvas extends JPanel
      {
        private AffineTransform       at, rotate, scale;
        private Rectangle2D.Double    r;
        public RectangleCanvas()
        {
    	  r = new Rectangle2D.Double(50.0, 50.0, 100.0, 100.0);
    	  rotate = AffineTransform.getRotateInstance(0.75, 100.0, 100.0);
    	  scale  = AffineTransform.getScaleInstance(3.0, 2.0);
    	  at     = new AffineTransform();
        }
        public void paint(Graphics g)
        {
    	  Graphics2D     g2;
	  Shape          s;
	  g2 = (Graphics2D)g;
	  at.setToIdentity();
	  at.preConcatenate(rotate);
	  at.preConcatenate(scale);
	  s = at.createTransformedShape(r);
	  g2.draw(s);
        }
      }
      
      What will be rendered the first time a RectangleCanvas
      is painted?  What will be rendered the second time it is painted?
      
            RectangleCanvas class above so that it
      contains a second rectangle with parameters (50, 50, 100, 100).
      The original rectangle must be rendered first in opaque red and
      the "new" rectangle must be rendered second in 50% transparent
      blue.  The background must be opaque white.
      
            paint method that is passed a 
      Graphics object, returns nothing, and draws a
      red rectangle centered in a solid black background.
      
            
    private JButton                   toggle;    
    private JLabel                    light;       
    
    private static final String       OFF   = "Off";
    private static final String       ON    = "On";
    private static final String       SPACE = " ";
    
               
    complete the following fragment so that toggle
    is 100 pixels by 50 pixels with its upper-left corner
    at (50,100) and light is 100 pixels by 50 pixels 
    with its upper-left corner at (250,100).
    
       JPanel                    contentPane;       
              
       contentPane = (JPanel)rootPaneContainer.getContentPane();   
       contentPane.setLayout(null);
       
       toggle      = new JButton();
       toggle.setText(ON);       
       light       = new JLabel();
       light.setText(SPACE);       
       light.setBackground(Color.BLACK);
       light.setOpaque(true);       
    
               
            this can respond to toggle being pressed?
    
            light will switch between black (when
    off) and white (when on).  Specifically, when the ``On''
    button is pressed the background color of light
    should be set to Color.WHITE and the text of
    toggle should be set to OFF.  On the
    other hand, when the ``Off'' button is pressed the background
    color of light should be set to
    Color.BLACK and the text of toggle
    should be set to ON.
    
    public void actionPerformed(ActionEvent event)
    {
       String   actionCommand;
       
       actionCommand = event.getActionCommand();
    }
    
               
            OnOffApplication that extends
    JApplication.
    
            ConvolveOp class.  How does this compare with
    requiring the user to compose kernels "by hand"?  Would it make sense
    to use the composite pattern with the 
    BufferedImageOp class?  Why or why not?
    
            | 0 | 0 | 0 | 0 | 
| 0 | 1 | 1 | 0 | 
| 0 | 0 | 0 | 0 | 
| 0 | 0 | 0 | 0 | 
and the following 3x3 kernel:
| 0 | 1 | 0 | 
| 0 | 0 | 0 | 
| 0 | 0 | 0 | 
What black-and-white "destination" image will result from applying a convolution with the above kernel to the above "source" image (when no operation is applied along the edges)?
               
     and would like
     us to develop a GUI component that renders such an image.  
     Prof. Bernstein has written part of a FrontWall class
     for this purpose.  You must complete the 
     renderBackground() method.
     
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
/**
 * A GUI component that displays the front wall of a classroom
 */
public class FrontWall extends JPanel
{
    protected double               imageHeight, imageWidth;
    protected double               wallHeight, wallWidth;
    protected Image                image;                   
    
    /**
     * Default Constructor
     */
    public FrontWall()
    {
       super();
       ImageIcon     icon;
       // Load the background image
       icon        = new ImageIcon("frontwall.gif");
       image       = icon.getImage();
       // Get the width and height of the background image
       imageHeight = (double)image.getHeight(null);
       imageWidth  = (double)image.getWidth(null);
    }
    /**
     * Render this component
     *
     * @param g   The rendering engine to use
     */
    public void paint(Graphics g)
    {
       super.paint(g);       
       Dimension          d;
       Graphics2D         g2;
       
       
       g2 = (Graphics2D)g;
       // Determine the size of this component
       d = getSize();
       wallWidth  = (double)d.width;
       wallHeight = (double)d.height;
       
       renderBackground(g2);
    }
    
    /**
     * Render the background image on this component.  When rendered,
     * the image must fill this component (that is, it must be
     * wallWidth x wallHeight pixels), even if it changes its aspect
     * ratio.
     *
     * @param g2         The rendering engine to use
     */
    protected void renderBackground(Graphics2D g2)
    {
        // YOUR CODE HERE!
    }
    
}
    
               
            BufferedImageBinaryOp interface that contains
    the requirements of dual-source/single-destination operations
    performed on BufferedImage objects.  Should this
    interface extend BufferedImageOp?  Why or why not?
    
            DifferenceOp class that implements
    the BufferedImageBinaryOp interface in the previous
    question.  The destination image `returned' by the
    filter() method must contain all of the pixels that
    are different in the two source images.
    Specifically, 
    the pixel in the result should be black if the corresponding
    pixels in the two source images are "the same" and should be
    red if they are "different".  This class must have
    an explicit value constructor that is passed a tolerance and a
    Metric that will be used by the filter()
    method to determine if the pixels are "different" or not.  
    It must also have a default constructor that assumes a
    tolerance of 0.
    
            Copyright 2025