Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am still new to Java Language, so please comment out lines so I can understand easily! thank you so much The RecursionP2 class will

I am still new to Java Language, so please comment out lines so I can understand easily! thank you so much

The RecursionP2 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.
  • 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.

Example

Original: [2, 4, 6, 8, 10] reverseList(): [10, 8, 6, 4, 2] toOddList(): [4, 8] toEvenRevList(): [10, 6, 2] retPenultimate(): 10 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions

Question

What are the challenges associated with tunneling in urban areas?

Answered: 1 week ago

Question

What are the main differences between rigid and flexible pavements?

Answered: 1 week ago

Question

What is the purpose of a retaining wall, and how is it designed?

Answered: 1 week ago

Question

How do you determine the load-bearing capacity of a soil?

Answered: 1 week ago

Question

what is Edward Lemieux effect / Anomeric effect ?

Answered: 1 week ago

Question

love of humour, often as a device to lighten the occasion;

Answered: 1 week ago

Question

orderliness, patience and seeing a task through;

Answered: 1 week ago

Question

well defined status and roles (class distinctions);

Answered: 1 week ago