Test2
and save your class in a file named
Test2.java
.
submit 1020 Test2 Test2.javaYou may submit your solution more than once. Additional documentation about the
submit
command can be viewed by typing man submit
.
Enter an integer of arbitrary size: 1234567890123456789012 Enter the exponent: -5 Out of range! Enter the exponent: 300 Out of range! Enter the exponent: 3 The integer raised to the exponent yields the power: 1881676372353657772545135432936336834499920430144437261088849728 This power is bigger than ten.
The app starts by prompting for an integer and then reading it on the next line.
You can assume, as a precondition, that the entry does indeed represent an integer,
i.e. a sequence of one or more digits optionally preceded by a minus sign.
Note, however, that since the number of digits in the entry can be very large, you
should read it via nextLine
and store it as a string. Such an entry
should not be treated as an int
or any other primitive type.
The app then prompts for an exponent and reads it on the next line.
You can assume, as a precondition, that this entry is an int
,
and hence, you can read it via nextInt
and store it in an
int
variable.
The app then validates the exponent to ensure it is between 2 and 100, inclusive. If not, the app issues an out-of-range message and then re-prompts. This prompt-input-validation cycle is repeated indefinitely until a valid exponent is entered.
It is recommended that you complete the development and testing of this phase and then submit your app before proceeding to the next phase.
Next the app computes the power ne
, where
n
is the arbitrary-sized integer stored in the string and
e
is the exponent stored in an int
. This
computation cannot be done via the pow
method of the
Math
class because of the involved size. Instead, the
app must use the services of the BigInteger
class of
the standard Java library. Examine the API of that class and look for
a constructor that takes a string; a method that raises a big integer
object to an int
exponent; and a toString
method suitable for output.
It is recommended that you complete the development and testing of this phase and then submit your app before proceeding to the next phase.
Finally, the app outputs a line indicating whether the computed power
is bigger than, less than, or equal to 10. To achieve this, you may
want to benefit from the fact that the BigInteger
class
has a field that represents 10 as a big integer.
Make sure you submit your app after completing the development and testing of this phase.