This assignment continues with 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.
Keep track of the time you spend on this assignment. When you submit it, tell us how many hours you spent on it.
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.
The deadline is Monday, 29 September, so that it is completed before the first prelim. Because you have a lot of work to do, including studying for the prelim, we have considerably reduced the work involved in this assignment by removing 5-6 functions from previous years.
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. 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 Rhino of A1: (1) a static variable and (2) more comparison methods, using boolean expressions.
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. Provide suitable test cases.
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.
RhinoTester
.
Then proceed to the next function. Method | Description |
---|---|
isMotherOf(Rhino r) |
= "r is not null, and this rhino is r's mother". |
isFatherOf(Rhino r) |
= "r is not null, and this rhino is r's father". |
isParentOf(Rhino r) |
= "r is not null, and this rhino is r's parent". |
isBrother(Rhino r) |
= "r is this rhino's brother".
Precondition: |
The names of your methods much match those listed above exactly, including capitalization. The number of parameters and their order and types must also match. The best way to ensure this is to copy and paste. Our testing will expect those method names 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 writing 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 objects.
Finally, isParentOf should be written to call isFatherOf and isMotherOf. We want you to begin seeing how a program can call methods already written instead of doing duplicate work themselves.
Your new method bodies should have no if statements or conditional expressions.
&&
(AND), ||
(OR), and ! (NOT), are sufficient to implement
all four functions. You will lose points for using if
statements or conditional expressions. .equals
to compare objects
(including String objects) for equality, but when you want to test whether two objects are or are not actually not the same, use ==
.null
, is there at least one test
case that has a call on the function with that argument being null
;
If not, points will be deducted. 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.