Question
Create a class RandomInteger. This class should have an private ArrayList to store data. a. Create a constructor for the class to create an empty
Create a class RandomInteger. This class should have an private ArrayList to store data.
a. Create a constructor for the class to create an empty array list.
b. Create a public method (addToFront) that takes one parameter, an int. The int will be inserted as the first element of the ArrayList, moving all the other elements up by one position. Hint: Before you start writing code, read the descriptions of the relevant methods in the API for ArrayList.
c. Create a public method (addToBack) that takes one parameter, an int. The int will be inserted as the last element of the ArrayList.
d. Create a public method (addSorted) that takes one parameter, an int. Assuming the ArrayList is sorted, the int should be inserted in the correct location that would keep the array sorted (you do not need to check if the array is sorted. Just assume it is).
e. Create a public method (productSorted) that takes one parameter, an int. Assuming the ArrayList is sorted, the int should be multiplied by the first int in the ArrayList, with the product replacing the first int and then being moved to the correct location that would keep the array sorted (you do not need to check if the array is sorted. Just assume it is).
f. Create a public method (selectionSort) that sorts the ArrayList using the selection sort algorithm (see here). g. Return an int array whose entries are equal to the ArrayList. This array should be used to perform your JUnit test using the assertArrayEquals method.
g. Return an int array whose entries are equal to the ArrayList. This array should be used to perform your JUnit test using the assertArrayEquals method.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started