Class Name: Bases
Method Name: adder
Implement a class Bases, which contains a method adder. The method takes two
Strings as parameters representing numbers in a certain number base and an int
that is that base. The method returns the sum of the numbers, also in the same
Adding numbers in bases other than 10 is similar to adding numbers in base 10.
Start at the least significant digit, add, and carry... There is a carry when
the sum is greater than or equal to the number base.
The base will be at most 16.
For base 16, the digits in order are:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
For any base b less than 16, the digits are the first b digits in the list above.
For example, add 613.56 and 104.4 in base 7:
(When adding the 4 and the 5 to the right of the decimal, the sum is 2 more
than the base, so there is a carry (1) and the sum minus the base (2) is
For example. add 1D.8 and 2.A in base 16:
When returning the sum, all leading 0s are truncated, unless the result is 0.
If the result is 0, the method returns "0".
If the fractional part is 0, the point and all 0s to its right are truncated.
If the fractional part is non-zero, all trailing 0s are truncated.
Here is the method signature (be sure your method is public):
String adder(String arg1, String arg2, int base)
TopCoder will ensure the following:
base is between 2 and 16, inclusive.
arg1 and arg2 have length at least 1 and at most 50.
arg1 and arg2 correctly represent non-negative numbers in the specified base
and contain only the characters '0' - '9' and 'A' - 'F' and '.'.
arg1 and arg2 may or may not have a '.', fractional part, or integer part.
The left most digit of arg1 and arg2 is the most significant digit. The right
most digit is least significant.
*If arg1 = 102.4, arg2 = 63.23, and base=10, the method returns 165.63
*If arg1 = 1D.EE, arg2 = D11.A12, and base=15, the method returns D30.A02
*If arg1 = .4, arg2 = .4, and base=8, the method returns 1