CS100J       Spring 2008      Assignment A3     Monitoring Rhinos 2    
Due (submitted on the CMS) by Tuesday, 19 September

This assignment is a continuation of A1. Start with your A1 classes Rhino and RhinoTester, which should be correct. You can group all your test cases for this assignment in one test procedure.

You may work in groups of 2, but you must do all the work together, sitting at the computer together. For example, for one person to write functions and the other person to write test cases for them, with no interaction, is dishonest. If you want to form a group. do it immediately. Both partners must take action in the CMS before the group will be formed.

We set a date of Tuesday, 19 September, so that this assignment will be completed before the first prelim. We know that you have a lot of work to do, including studying for the prelim. Therefore, we have reduced the work involved in this assignment by removing 4-5 functions from previous years (which had similar but not the same assignments).

In assignment A1, if you made a mistake, we asked you to fix it and resubmit. In this assignment, if you make a mistake, points will be deducted. And points may be deducted for lateness. Your new functions must have suitable javadoc comments, there must be appropriate test cases, and all methods should be correct. You can achieve all this most easily by writing and testing one method as a time.

In this assignment, you will add to the class of assignment 1: (1) a static variable, and (2) more comparison methods, using boolean expressions.

The steps to perform in doing this assignment

Step 1. Static variable. Add to class Rhino a private static variable that contains the number of Rhino objects that have been created so far. WHENEVER A RHINO OBJECT IS CREATED, THIS FIELD SHOULD BE INCREASED BY 1. And suitable test cases should be provided.

Add a static int function getPopulation, with no parameters, that will return the value of the static variable. Change the constructors so that they properly maintain the value of the static variable. Finally, add test cases to class RhinoTester to test whether the static variable is properly maintained.

Step 2. Comparison functions. Write the following functions, all of which produce a boolean value. Do one at a time: (1) write the function, then (2) test it thoroughly with test cases in class RhinoTester. Then proceed to the next function.

Method Description

isMother(Rhino r)

= "r is not null, and r is this rhino's mother".

isFather(Rhino r)

= "r is not null, and r is this rhino's father".

isParent(Rhino r)

= "r is not null, and r is this rhino's parent".

isBrotherOf(Rhino r)

= "this rhino is the brother of r". Note: Rhino A is called the brother of Rhino B if the two are different objects, if A is male, and if they have at least one parent in common. Precondition: r is not null.

isSisterOf(Rhino r)

= "this rhino is the sister of r". Note: Rhino A is called the sister of Rhino B if the two are different objects, if A is female, and if they have at least one parent in common. Precondition: r is not null.

The names of your methods much match those listed above exactly, including capitalization. The number of parameters and their order must also match. The best way to ensure this is to copy and paste. Our testing will expect those method name and parameters, so any mismatch will fail during our testing. Parameter names will not be tested —you can change the parameter names if you want.

Each method must be preceded by an appropriate specification, as a Javadoc comment. The best way to ensure this is to copy and paste from this handout. After you have pasted, be sure to do any necessary editing.

Note carefully the definition of brother and sister in the specs. Use these definitions when writng the methods.

In testing whether two rhino's are the same, do not use the field that contains their names. Instead, use the names on the tabs of their manila folders.

Your new method bodies should have no if statements or conditional expressions.

Directions

Submitting the assignment

Check these points before you submit your assignment:

Submit only files that end with the .java. Be careful about this, because in the same place as your .java files you may also have files that end with .class or .java~. but otherwise have the same name.