Question: JAVA public class Q4ArrayList { private static final int INITIAL_SIZE = 2; private static final double GROWTH_FACTOR = 1.5; T[] values = (T[]) new Object[
JAVA public class Q4ArrayList{ private static final int INITIAL_SIZE = 2; private static final double GROWTH_FACTOR = 1.5; T[] values = (T[]) new Object[INITIAL_SIZE]; int elements = 0; /** * Add a value to the tail of the list. * * @param value The value to be added. */ public void add(T value) { /* Unimplemented. Q4 i) [7 Marks] */ } /** * Remove the value at the specified index from the list. * * @param index */ public void remove(int index) { /* Unimplemented. Q4 ii) [7 Marks] */ } /** * @param index * @return The value at the specified index. */ public T get(int index) { if (index >= elements || index < 0) throw new IndexOutOfBoundsException(); return values[index]; } /** * @return the current size of the list. */ public int size() { return elements; } /** * Reverse the order of the elements of the list. */ public void reverse() { /* Unimplemented. Q4 iii) [6 Marks] */ } /** * @return A string representation of the list. */ public String toString() { String rtn = ""; for (int i = 0; i < elements; i++) { rtn += ((i != 0) ? " " : "") + values[i]; } return rtn; } }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
