Recursion Objectives of this Assignment Implement a set of recursive methods Lea
ID: 3707969 • Letter: R
Question
Recursion
Objectives of this Assignment
Implement a set of recursive methods
Learn how to use helper methods to solve recursive problems
Description
In this assignment you will write a number of recursive methods. Create a P11 project and class - you will implement the following interface: IP11.java
There is no input file.
P11
P11 is the only class in this assignment. You can exercise your methods more by extending the main method. We will test your code using a testClient class. Do not change the signature of the specified methods. You can however, and are advised to, create your own helper methods.
You will use ***RECURSION ONLY*** in this assignment, i.e., there will be no loops in any of the methods you implement. Any programs with loops found in them will be given a zero. Here are the methods in P11 that you will implement.
void printPattern(int n)
Precondition: n>0
Postcondition: print a pattern of n+1 lines ( 0 to n ):
line i (i = 0 to n) has i stars ("*"), followed by (n-i) stripes ("-")
For example, printPattern(3) prints:
hint: use a private recursive helper function, with more parameters, that does the work, e.g.:
You may need another helper function...
int convertNum(int[] num)
Precondition: num.length > 0, and num contains digits between 0 and 9 (inclusive)
Postcondition: return int representation of num
For example
hint: use a private recursive helper function, with more parameters, that does the work, e.g.:
Note: Your helper method signature may not match this, it is offered only as an example.
ArrayList intersection( ArrayList AL1, ArrayList AL2)
Precondition: AL1 and AL2 are not empty, and elements in AL1 are unique, and elements in AL2 are unique, (but AL1 and AL2 can contain the same elements)
Postcondition: return an ArrayList with elements that are in both AL1 and AL2, *** in the order they occur in AL1 ***, and *** leave AL1 and AL2 unchanged ***
For example:
hint: What kind of helper method would you use here?
IP11.java
Explanation / Answer
Hi Dear,
Please find my implementation:
Output:
testing printPattern
pattern 5:
-----
*----
**---
***--
****-
*****
testing convertNum
[1, 2, 3]: 123
testing intersection
[a, b, c] intersect [b, c, d, e] = [b, c]
Process finished with exit code 0
Please DONT forgot to rate my answer. We are working hard for you Guys!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.