Question: I need help with my programming assignment which requires a class level ArrayList to be reversed and manipulated through other methods. This assignment requires method
I need help with my programming assignment which requires a class level ArrayList to be reversed and manipulated through other methods. This assignment requires method overloading and I do not know where I am going wrong.
Java
The Recursion class will have only one class level variables: an ArrayList of Integers that will store a data set on which you will be performing different operations using recursive function. All these functions can also be done using iteration, however, you are restricted to only use recursion for full credit. Your program might be randomly checked and any non-recursive approach will be marked down.
The following non-static public methods have to be declared in your class:
-
Constructor (1-arg)
- The constructor will accept in an 1-D array of type int of unknown length and add every element to the class level ArrayList. There is no recursion required for this method.
-
reverseList(ArrayList)
- The method will accept in an ArrayList of type Integer and return a new ArrayList of type Integer that has all the elements in the reverse order. You are only allowed to use recursion for this method.
-
reverseList()
- The method will use the class level ArrayList and return a new ArrayList of type Integer that has all the elements in the reverse order. You are only allowed to use recursion for this method.
- Hint: This method is a special case of reverseList(ArrayList) and you are allowed to use that method if it helps.
-
toOddList(ArrayList )
- The method will use the class level ArrayList as a parameter and return a new ArrayList of type Integer that contains all the odd indexed numbered elements of the class level ArrayList. You are only allowed to use recursion for this method.
-
toOddList()
- The method will accept in an ArrayList of type Integer and return a new ArrayList of type Integer that contains all the odd indexed numbered elements of the class level ArrayList.
- Hint: This method is a special case of toOddList(ArrayList) and you are allowed to use that method if it helps.
-
toEvenRevList(ArrayList )
- The method will accept in an ArrayList of type Integer as a parameter and return a new ArrayList of type Integer that contains all the even indexed numbered elements of the class level ArrayList in reverse order. You are only allowed to use recursion for this method.
- You can use the reverseList() method as a helper method.
-
toEvenRevList()
- The method will use the class level ArrayList and return a new ArrayList of type Integer that contains all the even indexed numbered elements of the class level ArrayList in reverse order. You are only allowed to use recursion for this method.
- Hint: You can use toEvenRevList(ArrayList) or reverseList(ArrayList) as a helper method.
-
retPenultimate(ArrayList )
- The method will accept in an ArrayList of type Integer and return an int which is the last element of the ArrayList.If the list is empty/null, it should return -1. As usual, you are only allowed to use recursion for this method and the use of reverseList() is prohibited.
-
getList()
- The method would return the class level ArrayList. The return type is ArrayList.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
