CS 4448 - Spring 1998
Object-Oriented Programming and Design
Homework #7
Due on Tuesday, March 17 at the start of class.
You must print out your diagrams, your code, and a representative output
test suit of your TripleCalculator. Also email me the code.
Design a TripleCalculator and derive it from Calculator
Use the Calculator described in HW#5 and implemented in HW#6
You need to create a design for TripleCalculator to show how it works.
Show the class diagram of the TripleCalculator which must be derived
from Calculator. For this assignment do an interaction diagram with a
good test case. I will assume that all the details have already been
turned in for Calculator. So your design must give a VERY detailed
description of the TripleCalculator. You can show the design for your
Triple class which must be enhanced. When you follow the design and required
methods below you will have a TripleCalculator. This calculator will
NEVER have anything but a Triple in its memory or screen. If this is
not the case contact me before you turn in your assignment so we can
figure out if it is your oversight/loophole or mine.
Triple Class
You must take the Triple class from the web and go from there. You
could use your own but it has been pointed out that the designs might
be slightly different.
> - This method is binary and takes as parameter a Number,
Point, or Triple. The parameter is converted into a Triple using the
usual asTriple conversion. The return value is the boolean true or
false. True is only returned if x, y, and z are bigger. See Point for details.
dot: - Takes a parameter like the one described in ">" method. A
dot product is performed and a Number(float,int,etc.) is returned. The
equation for dot product is x1 * x2 + y1 * y2 + z1 * z2.
cross: - This method takes the same parameter as the ">"
method. The result is a new Triple. See sample code segment for the equation
Triple x: y * aTriple z - (z * aTriple y)
y: z * aTriple x - (x * aTriple z)
z: x * aTriple y - (y * aTriple x)
* - This method takes the same parameter as the ">" method. The
result is a new Triple with the value x1*x2,y1*y2,z1*z2.
/ - This method is the same as the "*" method with / replacing the
*. There is one difference, this method needs to return an error if
any division by zero will occur. Hint: your Point asTriple will have
a zero in the z position.
TripleCalculator Class
All the methods from Calculator should work when you are done.
clearMemory - This method is a unary. The memory is assigned the
triple (0@0@0). The old state/value of memory is returned.
clearScreen - Same as clearMemory except the new value is returned.
store: - This method will only take a Triple as parameter. The
Triple is stored to the screen in the usual/unchanged way screen does
stores.
cross: - This method takes whatever is okay by Triple cross:
method. The result is stored to the screen and returned.
dot: - This method takes whatever is okay by Triple dot: method.
The result is returned and nothing is stored to the screen.
ln - This method handles the implementation of ln for Screen value since
Triple does not know how to do it. Does a ln of x, y, and z and
stores the result to the screen and returns the value.
factorial - This method says that TripleCalculator does not do factorial.