Assignment #1: Reflection

A class is said to have a property prop of type SomeType if it has a pair of public non-static methods with the following signatures:
  // SomeType cannot be boolean
public void setProp( SomeType x );
public SomeType getProp( );
or:
  // type must be boolean
public void setProp( boolean x );
public boolean isProp( );
For example, class java.awt.Component has many properties, including:
PROPERTY NAME     TYPE
background        java.awt.Color
enabled           boolean
location          java.awt.Point
The derived class java.awt.Container has all those properties plus also, among others:
PROPERTY NAME     TYPE
font              java.awt.Font
layout            java.awt.LayoutManager

The Method to Implement

Implement a class with the public static methods shown below. You may add private helpers as you see fit.

package cop4338;

public class Utilities
{
    public static java.util.Map getProperties( Class cl )
      { ... }

    public static java.util.Map getPropertyVals( Object obj )
      { ... }
}

The getProperties method returns a Map that stores the properties (as defined above) of Class cl. In the map that is returned, the keys are Strings (each of which represents a property name) and the values are Class objects (each of which represents the corresponding property type).

The getPropertyVals method returns a Map that stores the current value of the properties (as defined above) of Object obj. In the map that is returned, the keys are Strings (each of which represents a property name) and the values are of type Object each of which represents the current value of the corresponding property type. You can get the value by invoking the appropriate get method (using the invoke method of class Method. Under no circumstances may either method produce any output at all, and you will receive a huge deduction if you violate this requirement.

What to Submit

Sumbit VIA PRINTOUTS AND NOT FLOPPIES your complete source code, and the results of testing getProperty on the following classes: String, java.awt.Rectangle, java.util.Date, and java.util.ArrayList. You will need to write an additional method that iterates through the Map that is returned by getProperties and outputs the properties in a style similar to the example above.

Next, create an object of type java.util.Date and invoke getPropertyVals on it, outputting the state of the Date object's properties. If you are careful, the routine that traverses the Map (written above) can be reused. Needless to say, you should invoke getProperties as part of your implementation.

Finally, you should write a class that you will pass as a parameter to getProperties to show that getProperties correctly:

In other words, your class will have lots of is. get and set methods, many of which don't qualify as a property, and your test program will verify that those properties don't appear in the Map that is returned when getProperties is called with your class as a parameter.

You will receive a huge deduction if you violate the submission requirements.

Note About Grading Style

I expect well-documented, properly indented code, consistently formatted and spaced code, with proper naming of methods and variables. Here are examples of deductions I will make.