|
Bill Teter email: william.teter@plattsburgh.edu |
|
|
project 2 -- recursion (Due September 14, 11:00 am) Create a directory called proj2. Write the code for the problems described below in this directory. Write and test a recursive static method that returns a String that represents any int n written in any base b between 2 and 16 inclusive. The parameters to this method will be n and b. Use the symbols "a" -- "f" to represent the values 10 .. 15. Your method must work for negative as well as positive integers, and zero. Place your code in a class called ToStringTest.java that has a main method that uses two command line arguments n, and b as follows: > java ToStringTest n b should call your method converting and printing the integer n to a string representation base b. In the documentation state what the complexity of your conversion routine is as a function of n. Write a second java program in a class called ToIntTest that tests a static method that converts any string representation of an integer in base b to its int value. Again b can be any value between 2 and 16. The main method should use two command line arguments: > java ToIntTest s b should call your static method and print the resulting int which should be the value of the string s interpreted as an int base b. Note that the string s may begin with '-' indicating a negative. In the documentation state the complexity of your conversion routine as a function of the length of the string s. Use Horner's rule in your conversion algorithm. Your conversion algorithm must be recursive. |