Answered step by step
Verified Expert Solution
Question
1 Approved Answer
package version_01; import java.util.Arrays; public class IntArrayList { private int[] element; private int size; private int DEFAULT_CAPACITY = 5; private int NOT_FOUND = -1; public
package version_01;
import java.util.Arrays;
public class IntArrayList {
private int[] element;
private int size;
private int DEFAULT_CAPACITY = 5;
private int NOT_FOUND = -1;
public IntArrayList() {
size = 0;
element = new int[DEFAULT_CAPACITY];
}
public IntArrayList(int capacity) {
size = 0;
element = new int[capacity];
}
private void doubleCapacity() {
/*
* Create new array of double the length
*/
int[] b = new int[element.length * 2];
/*
* Copy the elements of a to the corresponding indexes of b
*/
for (int i = 0; i
b[i] = element[i];
}
/*
* Reassign a reference to b
*/
element = b;
}
public void add(int value) {
if (size >= element.length) {
doubleCapacity();
}
element[size++] = value;
}
public void add(int index, int value) {
if (size >= element.length) {
doubleCapacity();
}
for(int i=size; i>index; i--) {
element[i] = element[i-1];
}
element[index] = value;
size++;
}
public void remove(int index) {
if (index >= 0 && index
for (int i = index; i
element[i] = element[i + 1];
}
element[--size] = 0;
}
}
public int get(int index) {
if (index = size) {
return NOT_FOUND;
}
return element[index];
}
public int size() {
return size;
}
private int indexOf(int x) {
for (int i = 0; i
if (x == element[i]) {
return i;
}
}
return -1;
}
public String toString() {
return Arrays.toString(Arrays.copyOf(element, size));
}
public static void main(String args[]) {
IntArrayList list = new IntArrayList();
for(int i=2; i
Use eclipse to do the following: 1. create a project folder Proj_Collections and within it create the following packages lists, tests and utility Proj IntArrayList project folder. in the tests package. 2. copy your IntArraylist class from your version 01 package of your 3. use your package called tests to create the JUnit test called ArrayListTest Notes: DO NOT use the wildcard (*) feature to import classes or interfaces from the standard library Each class or interface must be stated individually at the top of the class that uses it, i.e. you must import each class or interface separately. o o Methods must be listed in alphabetical order. o For this version of the ArrayList class, all methods of the ArrayList must use a "for loop" to perform iterations or repetitive access. Reading sections 2 to 4 of Chapter 15 in your Building Java Programs 4th Ed. Reges + Stepp) text book will be helpful in completing assignment. o 4. Create a Javadoc for the generic Array List collection class created. 5. Create a JUnit Test for the generic Array List collection class created. 6. Generate output according to the specifications indicated in this assignment. 7. Upload your work according to the Submission Protocol below list.add(i);
}
System.out.println(list);
}
}
Can you pleas add JUnit Test and comment on the class IntArrayList above code. Thank you.
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