I have an assignment listed below with my code. It is fairly short . If you all could review that would be awesome ! Thanks in advance .
***** Assignment *****'
Purpose: To write an application that uses recursion to solve a problem.
Details: Create a class called Power that computes the value of base exponent.
The class should have one recursive method:
public static int power(int base, int exponent) – Which computes the value of base exponent using recursion, returning the result. The recursion step should use the following relationship
base exponent = base x base exponent - 1
and the termination condition should occur when exponent is equal to 1, because
base 1 = base
NOTE: For the power method, assume the exponent parameter value is always greater than 0.
Create a second class called PowerTest that contains the main method, and tests the Power.power method. The test class does not need to ask for input from the user of the class, nor does it need to do any additional error checking.
Ensure that your program is properly formatted and it follows all Java naming conventions.
Line 3 is incorrectly indented, line 4 should be removed, and it is probably best to reduce lines 5‑8, which are incorrectly formatted too, to return ... ? ... : ...; Please read what you have been told to use as your base case (though I think your base case is better).
And what problems did you have with your test code?
There is an optimisation whereby you use exponent / 2 for even exponents and then square the result, but that may be more complicated than you want at this juncture.
You’re not following the instructions you were given:
1. Instructions say to terminate recursion when exponent is 1. Your code terminates when exponent is 0. It’s not logically wrong but it’s not what the instructions say.
2. Instructions say to assume exponent is always greater than 0. Your first “test” uses 0 as the exponent.
3. Indentation is not proper.
Paying attention to details like that is important. While your solution is more complete than what the instructions tell you to write, you’re still not following instructions. Indentation is a no-brainer. If you’re using an IDE that can auto format your code, then it’s a simple thing to comply to the requirement to indent your code properly.