... multiply
, add
and pow
. The expression in line 19 evaluates as follows:
-
First, the expression
rate.add(BigDecimal.ONE)
adds1
to therate
to produce aBigDecimal
containing1.05
—this is equivalent to1.0 + rate
in line 15 of Fig. 5.6. TheBigDecimal
constantONE
represents the value1
. ClassBigDecimal
also provides the commonly used constantsZERO
(0
) andTEN
(10
). -
Next,
BigDecimal
methodpow
is called on the preceding result to raise1.05
to the poweryear
—this is equivalent to passing1.0 + rate
andyear
to methodMath.pow
in line 15 of Fig. 5.6. -
Finally, we call
BigDecimal
methodmultiply
on theprincipal
object, passing the preceding result as the argument. This returns aBigDecimal
representing the amount on deposit at the end of the specified ...
Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.