You are working on a compiler of sorts that really just translates the user's code into another programming language which has its own compiler. You need to implement code translation for method calls in your language. The parameters passed into the method in your language will be given to you as a String[], params. You will also be given a translation descriptor, code, which tells you how to use the parameters in the code for the other language. The translation descriptor will have "$X" where X is a number between 1 and the number of parameters, inclusive, which signifies that the Xth parameter should be inserted in at that spot (1-based).
For instance, if params is {"x", "y", "z"} and code is "($2 + $3)/$1", you should return "(y + z)/x".
If there is ambiguity as to the number of the parameter, use the largest possible valid number less than or equal to the number of parameters - $105 would be parameter 10 followed by the character '5' if there are at least 10 parameters but less than 105 and would be parameter 1 followed by "05" if there are less than 10 parameters and at least one. Return code with all the substitutions made. |