|
Comp201: Principles of Object-Oriented Programming I
Spring 2006 -- HW 02
|
See Schedule Page for due date!
Save all of your work in a directory called HW02 on your U: drive
(Owlnet account) inside a directory called Comp201 .
You must use at least
Advanced Language Level for this assignment. Set DrJava to at
least "Advanced Language Level" before starting the assignment.
- (35 pts total) Write a JUnit test class called Test_MathFuncs
that tests the MathFuncs
class from HW01.
- Copy your MathFuncs
class from your HW01 folder to your HW02 folder. Do
a "File/Save As..." to save the file at the proper language level.
- Add a (private) field of type double
called _tol to Test_MathFuncs.
Initialize its value to 1e-15.
Use this variable for all the tolerance values needed below.
- (10 pts) Write a test method called test_add
that tests at least the following inputs (use multiple assertEquals
statements and be sure that your error strings are meaningful--i.e. indicative
of what is being tested!):
- 0+0
- 0 + a non-trivial value
- a positive value + a positive value
- pi + -pi (i.e. adding two non-trivial doubles to get zero)
- a postive non-trivial value + a negative non-trivial value
- (10 pts) Write a method called test_sqr
that tests at least the following inputs
- 0
- a non-trivial positive value whose square is known exactly
- a non-trivial negative value whose square is known exactly
- pi
- an integer
- (10 pts) Write a method called test_sumsqr
that tests at least the following
- 0 & 0
- 0 & a non-trivial value
- a positive value & a positive value
- pi & -pi
- a postive non-trivial value & a negative non-trivial value
- (5 pts) Adjust the value of _tol
to find the minimum power of ten that will enable all of the tests to
pass. That is, try 1e-12, 1e-13,
1e-14, 1e-15, 1e-16, 1e-17, etc.
- (20 pts total) Write and test an interface called IShape.
- (10 pts) Create a new interface called IShape
with an abstract method called getArea()
that take no input parameters and returns a double.
- (10 pts) Copy your Rectangle,
Triangle, Circle
and Square classes from
your HW01 folder into your HW02 folder. Do a
"File/Save As..." for each file to convert them them all to the new
language level.
- Modify each of them to implement IShape.
You will need to also make each
getArea() method
public.
- Test them using the following file:
Test_IShape.dj2 (Test_IShape.java
for Full Java users) download into your HW02 folder.
Examine the test code closely to
see how a variable of type IShape
can refer to different kinds of concrete shapes and give the proper
area for each of them. This is polymophism in action!
- (35 points total) Write and test a class called Pizza
- Pizza has the following
specification:
- a Pizza
has a double
which is the price of the pizza in dollars and
has an IShape
representing its shape.
- Pizza should have
a method called getPricePerSqInch
that takes no parameters and returns the dollars per square inch for
that pizza.
- (25 pts) Write the test class, Test_Pizza,
that tests Pizza given
a complete set of combinations of prices and shape and areas. Be sure
to test the cases where the values are zero! Write separate test methods
for each shape tested.
- (10 pts) Write the above getPricePerSqInch
method..
- Make sure all your test run and that they completely test your
Pizza
in all possible manners. See below for hints.
Hints:
- Double.isInfinite(x) will
return a boolean true if
the double value, x,
is infinite. It returns false
otherwise. Note that any non-zero value divided by zero will produce infinity.
- Double.isNaN(x) will return a boolean true
if the double value, x,
is not a number ("NaN"). It returns false
otherwise. Note that zero divided by zero will produce NaN.
- Consider using assertTrue
instead of assertEqual if
your test code only returns a single boolean value.
90 pts total.
When you have completed your homework, zip up the
entire HW02 directory and submit the zipped file
to your Comp201 WEBCT account.
Grading Criteria
- 35 pts total:
- 2 points for each of i-v
- 2 points for each of i-v
- 2 points for each of i-v
- 3 points if all tests pass, 2 points if no
lower power of ten allows all to pass
- 20 pts total:
- 3 points for IShape being there, 4 points for
IShape actually being an interface, 3 points for
correct declaration of getArea()
- 2 points for each of Rectangle,Triangle,Square,Circle to implement
IShape correctly, 2 points
for passing all the test cases
- 35 pts total:
- 4 pts for each type of Pizza being specifially tested (16
pts total, 4 for
each shape),
- 4 pts for having the correct fields.
- 5 pts for testing for Infinity
and/or NaN somewhere.
- 5 pts for returning the correct output,
5 pts if it does so by calling shape.getArea()
Last Revised
Thursday, 03-Jun-2010 09:50:12 CDT
©2006 Stephen Wong and Dung Nguyen