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)
reverseList(ArrayList)
reverseList()
toOddList(ArrayList )
toOddList()
toEvenRevList(ArrayList )
toEvenRevList()
retPenultimate(ArrayList )
getList()
Example
Original: [2, 4, 6, 8, 10] reverseList(): [10, 8, 6, 4, 2] toOddList(): [4, 8] toEvenRevList(): [10, 6, 2] retPenultimate(): 10
// do comment if any problem arises
// code
import java.lang.annotation.RetentionPolicy;
import java.util.*;
class RecursionP2 {
// class variable
ArrayList<Integer> array_list;
// constructor
RecursionP2(ArrayList<Integer> list) {
// create arralist
array_list = new ArrayList<>();
// copy given list to arraylist
for (int i = 0; i < list.size(); i++)
array_list.add(list.get(i));
}
// reverse given list
public ArrayList<Integer> reverseList(ArrayList<Integer> list) {
if (list.size() == 0)
return new ArrayList<>();
// call reverselist
ArrayList<Integer> temp = reverseList(new ArrayList<>(list.subList(1, list.size())));
// append 1st element to temp
temp.add(list.get(0));
return temp;
}
// this function returns reversed list in current object
public ArrayList<Integer> reverseList() {
return reverseList(this.array_list);
}
// temporary helper variable
boolean i = false;
public ArrayList<Integer> toOddList(ArrayList<Integer> list) {
if (list.size() == 0) {
i = false;
return new ArrayList<>();
}
i = !i;
boolean j = i;
ArrayList<Integer> temp = toOddList(new ArrayList<>(list.subList(1, list.size())));
if (!j) {
ArrayList<Integer> temp1 = new ArrayList<>();
temp1.add(list.get(0));
// copy temp to temp1
for (int i = 0; i < temp.size(); i++)
temp1.add(temp.get(i));
// insert first element
return temp1;
}
return temp;
}
public ArrayList<Integer> toOddList() {
return toOddList(this.array_list);
}
// returns even list
public ArrayList<Integer> toEvenRevList(ArrayList<Integer> list) {
if (list.size() == 0) {
i = false;
return new ArrayList<>();
}
i = !i;
boolean j = i;
ArrayList<Integer> temp = toEvenRevList(new ArrayList<>(list.subList(1, list.size())));
if (j) {
temp.add(list.get(0));
}
return temp;
}
public ArrayList<Integer> toEvenRevList() {
return toEvenRevList(array_list);
}
// returns last element
public int retPenultimate(ArrayList<Integer> list) {
if (list.size() == 1)
return list.get(0);
return retPenultimate(new ArrayList<>(list.subList(1, list.size())));
}
public ArrayList<Integer> getList() {
return array_list;
}
public static void main(String[] args) {
// testing above class
RecursionP2 testing = new RecursionP2(new ArrayList<Integer>(Arrays.asList(2, 4, 6, 8, 10)));
System.out.println("Original: " + (testing.getList()));
System.out.println("reverseList(): " + (testing.reverseList()));
System.out.println("toOddList(): " + (testing.toOddList()));
System.out.println("toEvenRevList(): " + (testing.toEvenRevList()));
System.out.println(
"revPenultimate(): " + testing.retPenultimate(new ArrayList<Integer>(Arrays.asList(2, 4, 6, 8, 10))));
}
}
Output:

I am still new to Java Language, so please comment out lines so I can understand...
Please Do It With Java. Make it copy paste friendly so i can
run and test it.
Thnak You.
Write programs for challenges 1 and 2 and 6 at the end of the chapter on Generics. 1) Write a generic class named MyList, with a type parameter T. The type parameter T should be constrained to an upper bound: the Number class. The class should have as a field an ArrayList of T. Write a public method named add, which...
Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 5×6=6+6+6+6+6 2. Recursive findings Write a recursive boolean method named reFinding. The method should search an array for a specified value, and return true if the value is found in the array, or false if the value is not found in...
java code level: beginner write a method sumList() public static Integer sumList(ArrayList<Integer> list) This method calculates the sum of all Integer values in a given ArrayList. For example, if ArrayList<Integer> list contains {1, 2, 3}, a call to sumList(list) should return 1+2+3, which is 6 as an Integer. Return null if the list is empty or null. Think about the base case. When should the method terminate/end? Under what condition should your method stop making recursive calls and return your...
Java, can you help me out thanks.
CSCI 2120 Introduction For this assignment you will implement two recursive methods and write JUnit tests for each one. You may write all three methods in the same class file. You are required to write Javadoc-style documentation for all of your methods, including the test methods. Procedure 1) Write method!! a recursive method to compare two Strings using alphabetical order as the natural order (case insensitive, DO NOT use the String class built-in...
Lab #4 – Recursive Methods for Generic ArrayList ----- JAVA The problem Use recursion to implement some list functionalities on an ArrrayList of generic type using type parameters in method definition Our goal for this lab is to continue using the divide and conquer approach of splitting a list into its head and tail and keep recursing on the tail (which happens to be smaller). However, instead of trying the approach on a string (a list of characters) we would...
write in java 1. Assume the availability of a method named makeLine that can be passed a non-negative integer n and a character c and return a String consisting of n identical characters that are all equal to c. Write a method named printTriangle that receives two integer parameters n and k. If n is negative the method does nothing. If n happens to be an even number, itsvalue is raised to the next odd number (e.g. 4-->5). Then, when k has the value zero, the method prints...
C# QUESTION Requirements Your task is to write a program that will print out all the s of the command line arguments to a program For example, given the arguments 'gaz, wx,and 'edc, your program should output wsxaazea Your implementation is expected to use Heap's algorithm according to the following pseudocode: procedure generatelk: integer, A: array of any): if k 1 then output A) else // Generate permutations with kth unaltered //Initially k length(A) // Generate permutations for kth swapped...
Java language
Any use of java.util.LinkedList is prohibited
Objective: The goal of this assignment is to practice recursion. ignment: The assignment requires writing recursive methods for some linked list operations. The use of loops in the recursive methods is strictly prohibited in this assignment. That is, you cannot use for, while, and do-while in the recursive methods you will write. You can only use a loop when you will initiate values for a linked list in the main method. You...
Programming Assignment #7 (Recursion) This assignment is to write some methods that perform simple array operations recursively. Specifically, you will write the bodies for the recursive methods of the ArrayRecursion class, available on the class web page. No credit will be given if any changes are made to ArrayRecursion.java, other than completing the method bodies Note that the public methods of ArrayRecursion – contains(), getIndexOfSmallest(), and sort() – cannot be recursive because they have no parameters. Each of these methods...
iii.print out the arraylist iv.reverse all the elements v.print
out this arraylist vi.make a clone of the arraylist
vii.remove all the elements at any odd index of the original
arraylist (not the cloned one)
viii.print out the original arraylist ix.reverse the cloned
arraylist x.print out the cloned arraylist (this arraylist should
still contain the original sequence of elements in order)
xi.merge the cloned arraylist to the original arraylist (please
think about what happens and draw a diagram for yourself to...