Introduction to Computer Science II by James Tam Return to the course web page

CPSC 233: Assignment 4 (Worth 10%)

 

This page is best viewed with Internet Explorer version 5+ and a computer with a sound card and a darn good set of speakers. 

 

Assignment description

Unless otherwise noted you can assume that the specifications for Assignment 3 also apply to this assignment.

 

Grading

Grades for working assignments:

C+ Level assignment

Implement a new class for a "Prosperous Biosphere" which is a subclass of the Biosphere class.  The birth and death rules for Critters is different in the Prosperous Biosphere:

Births: Occur in empty squares if there are 2 or 3 neighboring Critters.

Case 1: 2 Neighbors

     *
   
 *    

Case 2: 3 Neighbors

     *
 *  
 *    

    Deaths:

        Case 1: Critter dies of loneliness if it has no neighbors

     
   
     

        Case 2: Critter dies of over-crowding if it has 6, 7 or 8 or more neighbors

*
   
* *

If you are planning to implement the code for the "TerminatorCritter" (see Extra feature No. 1 below) then you will have to add another attribute to the Prosperous Biosphere:

Some behaviors associated with instances of the Prosperous Biosphere class include:

The starting positions for the Critters is different for this assignment and have been updated in the new biosphere class in the Assignment 4 directory.  You are free to copy  or modify this code but make sure that reference where you got the code from.   If you choose to write your own code to initialize the starting positions make sure that you get the starting positions exactly  the same!  Although you are free to use the biospheres for Assignment 3 for testing purposes your program must be able to handle the cases shown below in order to receive a grade of C+ or higher.

First set of required starting positions:

Second set of required starting positions:

 

Extra features:  Note that some of the features require more work to implement than the others so they are worth more than just a single letter step.

  1. Implement a Terminator Critter (+1 letter step for creating a Terminator Critter as a subclass of class Critter, +1 step if the Terminator can terminate other critters, +1 step if the Terminator can randomly move to another square, Max of 3 letter steps or one full letter grade for implementing all three features).

     

    1. Implement the Terminator Critter as a subclass of the Critter class (+1 letter step).  There will be exactly one Terminator in the biosphere and it will be displayed with the 'T' character.  The birth and death rules for the biosphere do not apply the terminator because does it not die and new terminators will never be born.  When you perform a count of the neighbors to determine if the Critters are born or die do not count the Terminator.  In the example below, the critter in the center would only have 3 neighbors counted:

     

         *
     * T
     *    

     

    With the addition of the Terminator critter there will now be two scan phases: 1) The normal births and deaths scan phase 2) This phase immediately is followed by a "specials" phase.  The extra array in the prosperous biosphere class called "specials" is needed to store the changes that occur because of the Terminator critter.  During the births and deaths scan phase the terminator lies dormant and does not do anything so the births and deaths are governed by the new rules of the Prosperous Biosphere:

During the "specials" phase the Terminator will first try to:  a) Terminate all  neighboring critters b) If the Terminator has no neighbors then it randomly move to anther square in the biosphere.

  1. Terminating other critters (+1 letter step) : During the specials phase any critters are in the squares that are adjacent to the Terminator will be "terminated" (star becomes a space).
  1. Random movement (+1 letter step): If during the specials phase there are no critters in the squares adjacent to the terminator then the terminator critter will randomly move to one of the unoccupied squares.   New randomly generated row and column coordinates will be generated if there is already a critter at the first set of coordinates.  Also your program must ensure that the Terminator actually does move (i.e., the new row and column coordinates aren't the same as the original values - if this is the case then another set of values must be generated).

Some behaviors of the Terminator class:

Finally you must set the starting position of the Terminator critter to row 3 and column 2 (see the documentation of the Prosperous biosphere class in the Assignment 4 directory for some guidance as to when you should do this in your program).

  1. Edit mode (+1 letter step):

The user can invoke this mode when the program asks if the user wishes to continue on for another generation.  Note that edit mode is not a listed option, it is implemented as a hidden "cheat" function.  The purpose is to provide an extra debugging tool for the programmer.  After the edit mode is invoked the program will display a message indicating it is now in edit mode and it will display the current state of the Prosperous biosphere (see the diagram below):

   

As the name implies edit mode allows the user to edit any square of the biosphere and either: 1) Empty the square of the existing critter 2) Or to add a critter to an empty square.  All three arrays will be effected by edit.  The Terminator critter cannot be added via edit mode because only one Terminator can exist at a time but the Terminator can be deleted.  After editing a square the user can either edit another square or exit edit mode and continue the simulation.

 

  1. Exception handling (+2 letter steps):

Your program implements a new exception "CritterAlreadyInSquareException" that is thrown whenever the program tries to birth a critter in a square that already contains a critter.   The method(s) that actually adds a critter to the biosphere (changes a space to a star) must throw this new exception.   The only exception is the initialization methods that determine the starting positions of the critters.  So this exception should be thrown whether the critter is added via the birth-and-death rules of the Prosperous biosphere or (more likely) when the user tries to manually add a Critter with during the edit mode.  Any methods that invoke the methods that throw this exception must be able to handle the exception through a try-catch block.  This new exception extends the existing java class "Exception". 

Grades for non-functional assignments

D level assignment

The student has invested considerable work in the assignment and the code compiles but it doesn't fulfill any of the above requirements.

D- level assignment

The student has invested considerable work in the assignment but it doesn't compile.

 

Other submission requirements

1. Good coding style and documentation:  They will play a role in determining your final grade for this assignment.  Your grade can be reduced by a letter step e.g., "A" to "A-" for poor programming style.

2. Method of submission: Do not hand in a paper typescript of this assignment.   Instead you must electronically submit all your source code before the due date.  Sometime after the due date you will then schedule some time to demo your assignment to your TA with the code that you electronically submitted.   (This means that you will not able to continue modify your assignment in time between the due date and when your demo has been scheduled).   The demos will be held during your regularly scheduled lab time and further details about which labs will be reserved for demos will be provided later during the term.   In addition to submitting your source that you include a file called "README".  This file must include all the pertinent information needed by your TA to mark your assignment:

3. Breaking down the assignment:

Classes that you need from Assignment 3: Classes you need to implement for this Assignment (which ones that you actually include will depend upon which functions are implemented by your program):

As was the case with Assignment 3, you have to employ some sort of debugging mechanism.  It is up to you if you choose to implement your debugging mechanism through the Debug class.

4. Handling the edge cases:  All of the grade levels shown above assume that you handle the edge cases (top and bottom rows, far left and right columns as well as the four corners) by using a 10x10 array and checking these conditions differently from the inner 8x8 squares.  If your program does handle these edge cases in this fashion but you otherwise implement the required functions, your submission will lose two letter steps.

 

Suggested Approaches to this Assignment:

  1. Start early!  You have several weeks to do this assignment and you will need it.   Don't wait until the night before the assignment is due.
  2. Take it in small steps, implement one feature at a time and make sure that it is properly working before moving on.
  3. Make liberal use of debugging aids such as including output statements in your program. Try to isolate your test cases (e.g., test the new "critter dies" and "critter is born" algorithm separately if you get really stuck).   Make liberal use of "print's" and "println's" to view your state of your biosphere at different stages of the scan process.  Doing things like this really helps you figure out where things are going wrong, this is why I listed it as one of the assignment requirements.
  4. If you need help and can't seem to get any (e.g., if my office hours really suck and you have a knack for catching me away from my desk then try email and I might be able to sit down with you some time).  Of course I must warn you all that I am more of a night person that a more person though so those 8 AM appointments are rather bad for me...
  5. Have fun! Remember this is only one assignment folks and not the whole semester. 

 

Relevant files

Source code files can be found in Unix in the directory /home/233/assignments/assignment4:

From Assignment 3:

  1. Debug.java: A class that you can use to fulfill the debugging requirement and to help you debug your program.
  2. Biosphere.java:  Note: I changed the code slightly because the initial positions are different from Assignment 3 so you will need the new initialization methods.

For Assignment 4:

  1. ProsperousBiosphere.  I provide a few hints in the documentation of this class as to how to get started for your Assignment 4.


New concepts to be applied to the assignment