// Only few methods are mentioned here //Do remaining methods to pass the test methods /** * Removes the specified (num) of the given element from the internal ArrayList of elements. * If num <= 0, don't remove anything. * If num is too large, remove all instances of the given element from the internal ArrayList of elements. * Example: * - For a defined CustomIntegerArrayList containing the integers: 1, 2, 1, 2, 1 * - Calling remove(2, 1) would remove the first 2 instances of 1 * - The CustomIntegerArrayList will then contain the integers: 2, 2, 1 * - For a defined CustomIntegerArrayList containing the integers: 100, 100, 100 * - Calling remove(4, 100) would remove all instances of 100 * - The CustomIntegerArrayList will then be empty * - For a defined CustomIntegerArrayList containing the integers: 5, 5, 5, 5, 5 * - Calling remove(0, 5) would remove nothing * * @param num number of instances of element to remove * @param element to remove */ public void remove(int num, int element) { // TODO } /** * Removes the specified number (num) of elements from the internal ArrayList of elements, starting at the given index. * If index < 0, don't remove anything and return an empty ArrayList. * If index is too large (>= to the size of this CustomIntegerArrayList), don't remove anything and return an empty ArrayList. * if num == 0, don't remove anything and return an empty ArrayList. * If the number of elements after the given index is less than the given num, * just remove the rest of the elements in the internal ArrayList. * Example: * - For a defined CustomIntegerArrayList containing the integers: 1, 2, 3, 4, 5 * - Calling splice(1, 2) would remove 2 and 3 (the 2nd and 3rd items) * - The CustomIntegerArrayList will then contain the integers: 1, 4, 5 * and this method would return a new ArrayList containing the removed elements: 2 and 3 * - For a defined CustomIntegerArrayList containing the integers: 1, 2, 3, 4, 5 * - In a call to splice(3, 4), the number of elements after the given index 3 is less than the given num 4 * - This would remove 4 and 5 (the 4th and 5th items) * - The CustomIntegerArrayList will then contain the integers: 1, 2, 3 * and this method would return a new ArrayList containing the removed elements: 4 and 5 * - For a defined CustomIntegerArrayList containing the integers: 100, 200, 500 * - Calling splice(1, 0) would remove nothing * and this method would return a new empty ArrayList * @param index to start on * @param num of items to remove * @return ArrayList of removed elements */ public ArrayList splice(int index, int num) { // TODO return null; } /** * Removes the specified number (num) of elements from the internal ArrayList of elements, * starting at the given index, and inserts the elements in the given otherArray at the given index. * Uses the splice(int index, int num) method. * If index < 0, don't remove anything or insert anything, and return an empty ArrayList. * If index is too large (>= to the size of this CustomIntegerArrayList), don't remove anything or insert anything, * and return an empty ArrayList. * if num == 0, don't remove anything or insert anything, and return an empty ArrayList. * If the number of elements after the given index is less than the given num, * just remove the rest of the elements in the internal ArrayList. * Example: * - For a defined CustomIntegerArrayList containing the integers: 1, 2, 3, 4, 5 * - Calling splice(1, 2, [6, 7]) would remove 2 and 3 (the 2nd and 3rd items), * and insert 6 and 7 at index 1. * - The CustomIntegerArrayList will then contain the integers: 1, 6, 7, 4, 5 * and this method would return a new ArrayList containing the removed elements: 2 and 3 * - For a defined CustomIntegerArrayList containing the integers: 1, 2, 3, 4, 5 * - In a call to splice(3, 4, [1000, 1001]), the number of elements after the given index 3 is less than the given num 4 * - This would remove 4 and 5 (the 4th and 5th items) and insert 1000 and 1001 at index 3. * - The CustomIntegerArrayList will then contain the integers: 1, 2, 3, 1000, 1001 * and this method would return a new ArrayList containing the removed elements: 4 and 5 * - For a defined CustomIntegerArrayList containing the integers: 100, 200, 500 * - Calling splice(1, 0, [700]) would remove nothing and insert nothing * and this method would return a new empty ArrayList * - For a defined CustomIntegerArrayList containing the integers: 5, 2, 7, 3, 7, 8 * - Calling splice(6, 3, [9]) would remove nothing and insert nothing * and this method would return a new empty ArrayList * @param index at which to remove and add the elements * @param num of elements to remove * @param otherArray of elements to add * @return ArrayList of removed elements */ public ArrayList splice(int index, int num, int[] otherArray) { // TODO return null; }
// Only few methods are mentioned here
//Do remaining methods to pass the test methods
/**
* Removes the specified (num) of the given element from the internal ArrayList of elements.
* If num <= 0, don't remove anything.
* If num is too large, remove all instances of the given element from the internal ArrayList of elements.
* Example:
* - For a defined CustomIntegerArrayList containing the integers: 1, 2, 1, 2, 1
* - Calling remove(2, 1) would remove the first 2 instances of 1
* - The CustomIntegerArrayList will then contain the integers: 2, 2, 1
* - For a defined CustomIntegerArrayList containing the integers: 100, 100, 100
* - Calling remove(4, 100) would remove all instances of 100
* - The CustomIntegerArrayList will then be empty
* - For a defined CustomIntegerArrayList containing the integers: 5, 5, 5, 5, 5
* - Calling remove(0, 5) would remove nothing
*
* @param num number of instances of element to remove
* @param element to remove
*/
public void remove(int num, int element) {
// TODO
}
/**
* Removes the specified number (num) of elements from the internal ArrayList of elements, starting at the given index.
* If index < 0, don't remove anything and return an empty ArrayList.
* If index is too large (>= to the size of this CustomIntegerArrayList), don't remove anything and return an empty ArrayList.
* if num == 0, don't remove anything and return an empty ArrayList.
* If the number of elements after the given index is less than the given num,
* just remove the rest of the elements in the internal ArrayList.
* Example:
* - For a defined CustomIntegerArrayList containing the integers: 1, 2, 3, 4, 5
* - Calling splice(1, 2) would remove 2 and 3 (the 2nd and 3rd items)
* - The CustomIntegerArrayList will then contain the integers: 1, 4, 5
* and this method would return a new ArrayList containing the removed elements: 2 and 3
* - For a defined CustomIntegerArrayList containing the integers: 1, 2, 3, 4, 5
* - In a call to splice(3, 4), the number of elements after the given index 3 is less than the given num 4
* - This would remove 4 and 5 (the 4th and 5th items)
* - The CustomIntegerArrayList will then contain the integers: 1, 2, 3
* and this method would return a new ArrayList containing the removed elements: 4 and 5
* - For a defined CustomIntegerArrayList containing the integers: 100, 200, 500
* - Calling splice(1, 0) would remove nothing
* and this method would return a new empty ArrayList
* @param index to start on
* @param num of items to remove
* @return ArrayList of removed elements
*/
public ArrayList<Integer> splice(int index, int num) {
// TODO
return null;
}
/**
* Removes the specified number (num) of elements from the internal ArrayList of elements,
* starting at the given index, and inserts the elements in the given otherArray at the given index.
* Uses the splice(int index, int num) method.
* If index < 0, don't remove anything or insert anything, and return an empty ArrayList.
* If index is too large (>= to the size of this CustomIntegerArrayList), don't remove anything or insert anything,
* and return an empty ArrayList.
* if num == 0, don't remove anything or insert anything, and return an empty ArrayList.
* If the number of elements after the given index is less than the given num,
* just remove the rest of the elements in the internal ArrayList.
* Example:
* - For a defined CustomIntegerArrayList containing the integers: 1, 2, 3, 4, 5
* - Calling splice(1, 2, [6, 7]) would remove 2 and 3 (the 2nd and 3rd items),
* and insert 6 and 7 at index 1.
* - The CustomIntegerArrayList will then contain the integers: 1, 6, 7, 4, 5
* and this method would return a new ArrayList containing the removed elements: 2 and 3
* - For a defined CustomIntegerArrayList containing the integers: 1, 2, 3, 4, 5
* - In a call to splice(3, 4, [1000, 1001]), the number of elements after the given index 3 is less than the given num 4
* - This would remove 4 and 5 (the 4th and 5th items) and insert 1000 and 1001 at index 3.
* - The CustomIntegerArrayList will then contain the integers: 1, 2, 3, 1000, 1001
* and this method would return a new ArrayList containing the removed elements: 4 and 5
* - For a defined CustomIntegerArrayList containing the integers: 100, 200, 500
* - Calling splice(1, 0, [700]) would remove nothing and insert nothing
* and this method would return a new empty ArrayList
* - For a defined CustomIntegerArrayList containing the integers: 5, 2, 7, 3, 7, 8
* - Calling splice(6, 3, [9]) would remove nothing and insert nothing
* and this method would return a new empty ArrayList
* @param index at which to remove and add the elements
* @param num of elements to remove
* @param otherArray of elements to add
* @return ArrayList of removed elements
*/
public ArrayList<Integer> splice(int index, int num, int[] otherArray) {
// TODO
return null;
}
Trending now
This is a popular solution!
Step by step
Solved in 6 steps with 3 images