Check04E (TS = 15)

Download the jar file typex.jar (the file has been updated on October 9, 10:30am) and save it in the same directory as type.jar. typex.jar should already be part of your CLASSPATH.

Create the program named Check04E that prompts the user to enter the initial value and the final value. Then it computes the rate of return which is defined as 100 * (final value - initial value) / initial value.

You may assume that the initial and final values are nonnegative real numbers that can be represented as a BigDecimal (this class is part of the package java.math). In your code, you do not need to use any variables of type double.

Print the results as in the following five sample runs. The input provided by the user is typeset in boldface. Note that the app crashes in the fourth and fifth sample runs.

Initial value: 1
Final value: 2
Rate of return: 100%
Initial value: 2.5
Final value: 0
Rate of return: -100%
Initial value: 1
Final value: 100000000000000000000000000000001
Rate of return: 10000000000000000000000000000000000%
Initial value: 0
Final value: 1
Exception in thread "main" java.lang.ArithmeticException: Division by zero
        at java.math.BigDecimal.divide(BigDecimal.java:1587)
        at Check04E.main(Check04E.java:??)
Initial value: 3
Final value: 4
Exception in thread "main" java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
        at java.math.BigDecimal.divide(BigDecimal.java:1616)
        at Check04E.main(Check04E.java:??)

To check whether your code is correct, you can use eCheck. You are advised to use the offline mode first. Once your code is correct (worth 3 marks) and you are happy with your style (worth 2 marks), you can switch to the online mode and submit your solution. For style, you should adhere to the code conventions described in Appendix C of the textbook.