Introduction |
This programming assignment is primarily designed to give you experience
reading classes in an inheritance hierarchy (which also includes abstract
classes) and writing new classes that extend it.
Objects from these classes will be used in an Model-View-Controller
implementation of a simple GUI application: a simulation that allows the
user to choose/place objects in a simulated world and then have them
interact.
The Model class, which you will also write, uses an array to
store/process references to all these objects.
The application allows the user to place these objects into a simulation then
it animates their behavior, which often includes interesting interactions
between the objects.
A major goal of this assignment -the only one dealing with object-oriented design- is to think about elegant ways to use inheritance (as well as delegation) to write short and perspicuous classes. I have supplied a complete Application class, and complete Controller and View classes; from the hierarchy, I have supplied the following complete abstract classes
|
  |
When you write these classes, you should not modify any code written in their superclasses: you should also not duplicate any fields or methods that are inherited, although you can override such methods (whose bodies, in part, might call the overridden methods by using super) as well as add new methods. The update method, which implements the different behavior of each Simulton will be generally implemented to combine various behaviors from class that implement the Behavior interface. Likewise, the graphic representation for each Simulton will be selected from the classes that implement Displayable (including ColoredCircle and Icon -which displays any picture).
In addition to writing these classes, you must develop one more class, in this hierarchy, that exhibits some interesting behavior. Please document its behavior in the comments for its class, which should be called SpecialSimulton so that we can easily find it. I have provided various suggestions at the end of this assignment for special behaviors, but I'll be happest if you invent your own. As always, you can check the behavior of your program against mine by downloading and running my Executable, to help you understand the specification of the problem and observe the programmer/user interaction (and the behaviors of the objects in the simulation) that you are to implement Instead of starting with empty project folders, download and unzip the Start Project Folder which contains all of the classes that you are to use. Write your program in this project folder whose name combines your names (when programming in pairs) and the program number (e.g., pattis-stehlik-6). Then zip this folder and dropoff that single zip file. If you are programming in a pair you should submit only one project: either partner can submit it. Finally, you can download the Raw Javadoc for the prewritten classes supplied in this assignment; I have not written Javadoc comments for these classes, but I have built the Javadoc from the raw classes (you might find it more useful to read the details of these classes in the Eclipse editor). This shows all the private and class-friendly entries, because you are reading this code as the writer/maintainer of the simulation package. Click on the index.html file that it contains to bring up the Javadoc. |
Details |
This section contains some details about the Model class for this
simulation, and about the classes in the inheritance hierarchy described
above.
The class files themselves also contain useful documentation, mostly in their
header comments: please read them (especially in MoveableSimulton,
which describes how to manipulate velocities represented by angles/speeds).
I have put these in a skeleton Javadoc API (what you get when you Javadoc
classes that have no Javadoc comments; good, but not great, information).
Also, plan on reading the JavaDoc for Sun's API, as it relates to classes like
Math, Color, Dimension, Point, Rectangle,
and any others that you may run across while you read the methods in these
classes.
Note that calling Math.random() produces a double value in the range [0,1),which means 0<= Math.random() < 1 (note the different relational operators). You can write larger expressions to produce random numbers in the specified ranges. Be careful as some quantities are represented as double and others as int.
The Model class must support a variety of methods, which are called by the Controller and View classes, as well as the Simulton classes in the hierarchy (to locate other simultons, remove them from the simulation, etc). The main data structure in the Model is one "polymorphic" array (you can use a collection class if you want, but we won't quite cover the List or Set interface until next week) that stores all the objects in the simulation (all descended from Simulton); of course, it must also store how much of this array is used, and be able to add (possibly with the length doubling) and remove values from this array. The Model class already defines the trivial setView method, along with getEnclosingBox, which uses the view instance variable defined there. Specifically, methods in the Controller class call
In addition, methods in the View class (explicitly or implicitly) call
|
Iterative Enhancement |
It is critical that you not try to write all the code at once; as you
write/debug code for some classes, you will learn better how to write it for
other classes.
If you try to write everything at once, you are likely to end up in an
undebuggable swamp of code.
I suggest that you follow the instructions below when tacking the parts of
this assignment.
In preparation for writing Simulton classes, first examine the Behavior interface. The update methods in classes descended from Simulton can construct one or more objects implementing this interface, and delegate tasks to them to achieve the overall required behavior. For example, see the StraightBehavior (used by balls when they move) and the AlarmBehavior (which you will find useful for pulsating holes that shrink after every 50 updates). Beside these, I wrote the following classes for this assignment; each implements a Behavior (some of which have extra methods, beyond doIt as appropriate).
Many of the behavior classes are quite generic, taking Decision parameters that embody necessary details, so you'll also be writing classes that implement this interface (possibly you'll find it useful to define anonymous ones). Useful operations inside the isOK methods in these classes are the instanceof operator and the distance method (on Point arguments). You might find it neccessary to declare and initialize interesting instance variables in classes that implement this interface. To actually start this assignment, first stub in all the methods in the Model class and implement the minimal code for adding Ball objects to the model in the mouseClick method. All this code will primarily deal with storing an array of Simulton objects, to which objects can be added and removed. You should actually write initial versions of most of the useful Model methods here (some will be enhanced later): I wrote bodies for just methods 1 and 3-7 here. Test this code and ensure it is working (you should be able to add/remove Ball objects to the simulation) before continuing, since I have already written this class. Next, write the BlackHole class (study Ball first to understand how it works) and add it, and any classes that is uses (which implement the Behavior interface) to the project. After implementing this class, you must also define the getAllSatisfying and remove methods in Model and write nextObject and update mouseClick so that they work together to coordinate selecting and constructing different kinds of objects. Test the interactions between BlackHole and Ball objects. Next, write the Floater class and add it, and any classes that is uses (which implement the Behavior interface) to the project. If you have trouble using the Icon class, first test it behavior using a ColoredCircle. After implementing this class, you must update mouseClick to construct this kind of object and add it to the simulation too. Test the interactions between BlackHole and Floater objects. Next, write the PulsatingBlackHole class and add it, and any classes that is uses (which implement the Behavior interface) to the project. After implementing this class, you must update mouseClick to construct this kind of object and add it to the simulation too. Test the interactions between PulsatingBlackHole and both the Ball/Floater objects. Next, write the HuntingBlackHole class and add it, and any classes that is uses (which implement the Behavior interface) to the project. (Hint: A direct approach, and one not difficult to program, is to have this class extend the abstract MoveableSimulton and just mix in the required behaviors in its update method. A more interesting approach is to have this class extend the abstract MoveableSimulton, and then delegate some of its operation to a PulsatingBlackHole object, which is already written/debugged.) After implementing this class, you must update mouseClick to to construct this kind of object too. Test the interactions between HuntingBlackHole and Ball/Floater objects. Finally, specify and write your own subclass in the hierarchy to animate in some interesting way. Update mouseClick to construct this kind of object too (after the Special button is pressed). Specify its interesting behavior in the comments at the top of its file, and ensure that it works correctly. If you have no good ideas of your own, you might implement any of the the following ideas:
|
Extra Credit |
There are two points of extra credit on this assignment.
|