Your instructor will assign one or more of the following problems. Submit all appropriate files for grading, including code files, screen captures, supplemental files (e.g., image files), and text files.
Write a power()
method for your calculator that
computes xn
, i.e., x
raised to the
power n
, where x
is any real number and n
is an integer.
Exponentiation is available in Java via the method Math.pow()
but for this exercise you will implement the computation for yourself
using iteration. To avoid confusion with Math.pow()
,
you’ll call your method power()
.
Your method should handle negative exponents (i.e., xn for n < 0 is the same as 1/xn).
Add new tests to the CalculatorTest
class for the
new function.
Extra Credit: For extra credit, implement this function using recursion.