Labor – Parameter-Checks + TestMethods (based on Lab-02)
-
Use a copy of Lab-02 as a basis.
-
Add parameter checks to setters:
length
has to be between >0 and 100
width
between. >0 and 50 m
radius
between >0 and 50 m+height
between >0 und 30 m
density
between 100 and 20000 kg/m³If the params are invalid, nothing is changed, but an error massage is printed of a form similar to:
ERR in setXxx(..) - xxx invalid (>0 … 99): 200
To ensure valid values we should assign acceptable default values to all of the attributes (can be done directly at declaration, e.g.:
private int n = 1;
) -
create a test method for every class which calls all of the methods with valid and invalid parameters, check the return values and error messages.