next up previous
Next: What to turn in Up: Homework 3: Void Methods Previous: More dates

Multadd

Many computations can be expressed concisely using the ``multadd'' operation, which takes three operands and computes a*b + c. Some processors even provide a hardware implementation of this operation for floating-point numbers.

1.
Create a new project called Multadd.prj.

2.
Write a method called multadd that takes three doubles as parameters and that prints their multadditionization.

3.
In main test your method by invoking it with a few simple parameters, like 1.0, 2.0, 3.0. The result should be 5.0.

4.
Also in main, use your method to compute the following values:
  $\textstyle \sin \frac{\pi}{4} + \frac{\cos \frac{\pi}{4}}{2}$   (1)
  $\textstyle \log 10 + \log 20$   (2)

5.
Write a method called yikes that takes a double as a parameter and that uses multadd to calculate and print

\begin{displaymath}x e^{-x} + \sqrt{1 - e^{-x}}
\end{displaymath} (3)

HINT: the Math method for raising e to a power is Math.exp.



Allen B. Downey
1999-09-21