CPSC 111 2005/6 Winter Term 2, Assignment 3: Beasts


Contents: Details | Deliverables

Details

Out: Thu Mar 23 2006
Due: Fri Apr 7 2006, 5:00pm, both hard copy and electronic handin
Value: 4% of final grade (subject to instructor discretion)

Objectives:

Contents:
  • Description
  • Design
  • Download/API
  • Setting Up Your Project
  • Reflection Questions
  • Description

    Beasts are graphical objects that move around an onscreen window, showing their mood by their color. Your job is to control their behavior. Beasts are controlled by their brains, which set their direction of motion and mood. The behavior of a beast can also be influenced by the members of its pack.

    Your mission is to control the beasts by implementing three interfaces:

    You are provided with example classes that implement these interfaces. The DumbBrain class is a very simple IBeastBrain that moves in a straight line, with no mood changes. The RandomWalkingBrain is a slightly smarter IBeastBrain that needs to access information about the Beast's state, as stored in the BeastInfo class. It chooses its direction randomly, and its intensity gets lower as it ages. The AllBeastsPack is a very simple IPackFinder that returns all created Beasts as being pack members. The DumbSetup class is a simple IBeastProvider class that returns an array of newly created Beasts to the BeastSimulationProgram driver class in its setup method, so that they can be added to the scene. The requirements of this assignment are to create many more classes that implement these interfaces. Specifically: Beasts can, and often do, move out of the visible area of the window.

    If those descriptions above sound vague, it's because they are! For instance, how tight should the SpinnyBeast's circles be? It's up to you. As long as your beasts look right in the way they behave, and your documentation shows how you've fulfilled the specification, you'll get full marks. So make sure you comment your code carefully to justify your choices.

    Be careful of what assumptions you make when writing beast brains and pack finders. For example, remember that you may be dealing with an empty pack containing no beasts, or that there might be no leader. Your code should be robust and do something reasonable in these cases, not crash! Again, document your design choices.

    As usual, some bonus points are available for going above and beyond the call of duty, by implementing more or particularly impressive brains and packs.

    Beasts Design

    We have provided a framework for a working Beast package. You are required to create all the new classes listed above, implementing the three interfaces for brains, packs, and setup. The only code that you will need to change in the existing framework is the setup method in the BeastSimulationProgram, marked with "TODO". Here's a diagram of the three interfaces, with placeholders like "YOURBrains" for the classes that you need to write:

    The full framework is:

    All code that you add must be clear, easily readable, and documented with JavaDoc. Note that it is unlikely that the comments provided for an interface's methods are sufficient documentation for the methods of a class that implements it, so don't just copy them! Any significant or potentially confusing parts of methods should be documented; code that is reused in different parts of a class should be abstracted into a method; and methods that become overly long or complex should be broken down into simpler methods. Remember to explain in your comments all design decisions you made!

    Beasts Download/API

    Download the framework: Beasts.zip

    Includes these source files (no need to download separately):
    BeastSimulationProgram.java, AllBeastsPack.java, Beast.java, BeastInfo.java, BeastManager.java, BeastMood.java, Direction.java, DumbBrain.java, DumbSetup.java, IBeastBrain.java, IBeastProvider.java, IPackFinder.java, RandomWalkingBrain.java

    API documentation for Beast package:

    Optional Information (not needed for this assignment): If you're curious about how we implemented the graphical display, feel free to browse the documentation for the ACM packages. If you'd like to read about the design rationale for that set of packages, see the discussion from the ACM Java Task Force.

    Setting Up Your Project

    Setting up in Eclipse: Start by downloading the file Beasts.zip to your computer. Next, open Eclipse, and make a new Project named Beasts. Under the File menu select Import.... Select Archive file as the import source and browse to the Beasts.zip file that you just downloaded. For the Into folder, choose Beasts and hit Finish.

    Now, your project contains all the necessary code, but the acm.jar file is not on your classpath. Right-click on the Beasts project and select Properties. In the menu on the left, select Java Build Path. Select the Libraries tab on the right. Click Add Jars.... You should see Beasts in the dialog box that pops up. When you double-click on it, you should see the jar file acm.jar. Select it and hit OK.

    You should now be ready to solve the assignment in Eclipse.

    Setting up on the command line: Start by downloading the file Beasts.zip to whatever directory on your computer you'd like to work from. Next, unzip the file to that directory. (The Home Suite Home CD and the lab computers have FilZip for unzipping files; you may have another application.)

    To compile from the directory where you installed your code, use:

    javac -classpath .;acm.jar *.java

    To run from the directory where you installed your code, use:

    java -classpath .;acm.jar BeastSimulatorProgram
    Note the dot at the start of the classpath arguments! That's crucial so Java knows to look in the current directory for classes and files. On some computers, you may need to use :s rather than ;s in the commands above.

    Reflection Questions

    Be sure to answer these reflection questions after you finish the assignment. There are no right answers to these questions, and we don't expect more than a couple of sentences for each question. However, we will grade on your effort to answer throughtfully.
    1. Describe YourBrain and YourPackFinder. What nifty things can they do?
    2. Now that you know about inheritance, how could you have used inheritance in this project to make your program easier to write or more powerful.
    3. If Java didn't have polymorphism at all, how would you have done this project? Are interfaces and inheritance worth the complexity they add to the language?
    4. OPTIONAL: What was especially interesting or frustrating about this part of the assignment? What could we have done to make it better for you?
    Note: You should include your answers to the reflection questions in a separate text file from your code named README.txt. Please do not submit your questions in any format other than plain text. (Note that neither Microsoft Word nor PDF is plain text! Whatever editor you use to write your source code should be usable to write a plain text README.txt file.) You should answer the reflection questions for all parts of an assignment in the same README.txt file.


    Deliverables



    Last modified: 2006/04/03