Put all the methods in the previous five exercises into a package and class of your own creation. Be sure to choose sensible, easy-to-understand, hard-to-confuse, names for all packages, classes, and methods. Declare methods and fields static, final, and/or abstract when appropriate.
ComplexNumber
class discussed in last
week's class.
Define a reasonably named
package for financial classes. Place last week's Money
class
in this package.
Add an overloaded constructor
to the Money
class that only takes the number of dollars.
Add an overloaded constructor
to the Money
class that takes no arguments and initializes the object to $0.00.
equals()
method to the Money
class.
Define an exception class called MoneyOverflowException
which can be thrown
when an operation with Money
results in an over flow. Place this class
in the same finance package.
Rewrite the methods in the Money
class so that they recognize overflow
and throw a MoneyOverFlowException
if it occurs.
java.math
package to eliminate the possibility of overflow in
the Money
class.
java.math.BigDecimal
class
to provide 20 decimal digits of precision. Some hints:
setScale()
method with every iteration
is necessary
to keep the value of population from overflawing the memory of the computer.
compareTo()
and the Comparable
interface instead of either ==
or equals()
.