we using java code /** * DynamicArray.java * * Replace all //TODO tags with your code * * Note
that below the "//TODO" tag there may be * something like "return null;", "return 0;", etc. * That line
is just "stubbed in" so the class * will compile. When you add your code (one or many *
statements), you will want to delete the "stubbed" line. * By "stubbed in" we mean "mocked" or
"faked in" temporarily. * * When testing, construct using the static factory methods:
DynamicList.newEmpty() DynamicList.fromGrowthFactor(growthFactor)
DynamicList.from(arrayElements) */ package model.list; import java.lang.reflect.Array; import
java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiFunction; import
java.util.function.Consumer; import java.util.function.Function; import
model.linearpub.DynamicList; import model.linearpub.StructureIterator; public class
DynamicArray<E> implements DynamicList<E> { //--------------------------------- // Instance Variables
//TODO - declare instance variable(s) //--------------------------------- // Private Constructors /**
Constructs and returns new DynamicArray (no args constructor) */ private DynamicArray() {
this(defaultGrowthFactor()); } /** Constructs and returns new DynamicArray with "aGrowthFactor"
*/ private DynamicArray(double aGrowthFactor) { //TODO -- this is the constructor that should
//initialize the dynamic array as needed } //------------------------------------------------ public static double
defaultGrowthFactor() { //TODO - replace 0 with a good growth factor return 0; } protected static int
defaultInitialCapacity() { //TODO - replace 0 with a good initial capacity return 0; } //--------------------
List Statistics --------------------- /** * Return number of elements in this list. */ @Override public int
size() { //TODO return 0; } /** * Return true is this list contains no elements. */ @Override public
boolean isEmpty() { //TODO return false; } //------------------ Accessing Elements -------------------- /**
* Return element at given index. * Throws IndexOutOfBoundsException if passed index is invalid.
*/ @Override public E get(int index) { //TODO return null; } /** * Return first element * Throws
RuntimeException if list is empty */ @Override public E first() { //TODO return null; } /** * Return
last element * Throws RuntimeException if list is empty */ @Override public E last() { //TODO
return null; } /** * Return a new list containing the elements of this list * between the given index
"start" (inclusive) and * the given index "stop" (exclusive). * Throws IndexOutOfBoundsException if
either passed index is invalid. */ @Override public DynamicList<E> subList(int start, int stop) {
//TODO return null; } /** * Return index of first matching element (where searchFct outputs true) *
Return -1 if no match * Example usage (first list of integers, then employees): * index =
list.find(eaInteger -> eaInteger == 10); * index = employeeList.find(employee -> employee
.getFirstName().equals("Kofi.
we using java code DynamicArrayjava Replace all .pdf
1. we using java code /** * DynamicArray.java * * Replace all //TODO tags with your code * * Note
that below the "//TODO" tag there may be * something like "return null;", "return 0;", etc. * That line
is just "stubbed in" so the class * will compile. When you add your code (one or many *
statements), you will want to delete the "stubbed" line. * By "stubbed in" we mean "mocked" or
"faked in" temporarily. * * When testing, construct using the static factory methods:
DynamicList.newEmpty() DynamicList.fromGrowthFactor(growthFactor)
DynamicList.from(arrayElements) */ package model.list; import java.lang.reflect.Array; import
java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiFunction; import
java.util.function.Consumer; import java.util.function.Function; import
model.linearpub.DynamicList; import model.linearpub.StructureIterator; public class
DynamicArray<E> implements DynamicList<E> { //--------------------------------- // Instance Variables
//TODO - declare instance variable(s) //--------------------------------- // Private Constructors /**
Constructs and returns new DynamicArray (no args constructor) */ private DynamicArray() {
this(defaultGrowthFactor()); } /** Constructs and returns new DynamicArray with "aGrowthFactor"
*/ private DynamicArray(double aGrowthFactor) { //TODO -- this is the constructor that should
//initialize the dynamic array as needed } //------------------------------------------------ public static double
defaultGrowthFactor() { //TODO - replace 0 with a good growth factor return 0; } protected static int
defaultInitialCapacity() { //TODO - replace 0 with a good initial capacity return 0; } //--------------------
List Statistics --------------------- /** * Return number of elements in this list. */ @Override public int
size() { //TODO return 0; } /** * Return true is this list contains no elements. */ @Override public
boolean isEmpty() { //TODO return false; } //------------------ Accessing Elements -------------------- /**
* Return element at given index. * Throws IndexOutOfBoundsException if passed index is invalid.
*/ @Override public E get(int index) { //TODO return null; } /** * Return first element * Throws
RuntimeException if list is empty */ @Override public E first() { //TODO return null; } /** * Return
last element * Throws RuntimeException if list is empty */ @Override public E last() { //TODO
return null; } /** * Return a new list containing the elements of this list * between the given index
"start" (inclusive) and * the given index "stop" (exclusive). * Throws IndexOutOfBoundsException if
either passed index is invalid. */ @Override public DynamicList<E> subList(int start, int stop) {
//TODO return null; } /** * Return index of first matching element (where searchFct outputs true) *
Return -1 if no match * Example usage (first list of integers, then employees): * index =
list.find(eaInteger -> eaInteger == 10); * index = employeeList.find(employee -> employee
.getFirstName().equals("Kofi")); */ @Override public int findFirst(Function<E, Boolean> searchFct)
{ //TODO return 0; } /** * Return index of last matching element (where searchFct outputs true) *
E.g., if searching for employee with name "Kofi" and there is a match * at index=3 and index=8,
findLast will return 8 (the last matching index). * Hint: start search at end of list and work
backwards through list. * Return -1 if no match */ @Override public int findLast(Function<E,
Boolean> searchFct) { //TODO return 0; } //------------------- Setting Elements --------------------- /** *
Insert passed arg "newElem" into position "index" * Return previous (replaced) elem at "index" *
Valid "index" values are between 0 and "size - 1" * If "index" is invalid, throws
IndexOutOfBoundsException. */ @Override public E set(int index, E newElem) { //TODO return
null; } //------- Inserting, Appending & Replacing Elements -------- //------------------ (Dynamic
Behaviors) ------------------ /** * Add the passed element to start of list */ @Override public void
2. addFirst(E newElem) { //TODO } /** * Add the passed element to end of list */ @Override public
void addLast(E newElem) { //TODO } /** * Alias for "addLast" (same functionality) */ @Override
public void add(E newElem) { //TODO } /** * Add all elements from "otherDynList" into "this" list */
@Override public void addAll(DynamicList<E> otherDynList) { //TODO } /** * Add all elements
from passed fixed array "this" list */ @Override public void addAll(E[] array) { //TODO } /** * Shift to
the right the element currently at "insertIndex" (if any) and all elements to the right * Insert passed
arg "newElem" into position "insertIndex" * Valid "insertIndex" values are between 0 and "size" * If
index = "size" then it becomes a simple "add" operation * If "insertIndex" is invalid, throws
IndexOutOfBoundsException */ @Override public void insert(int insertIndex, E newElem) { //TODO
} //------------------- Removing Elements -------------------- //------------------ (Dynamic Behaviors) ---------
--------- /** * Remove first element * Return removed element * Throws RuntimeException if list is
empty */ @Override public E removeFirst() { //TODO return null; } /** * Remove last element *
Return removed element * Throws RuntimeException if list is empty */ @Override public E
removeLast() { //TODO return null; } /** * Reset the list so it is empty. * If list is already empty, then
do nothing * No action is performed on the elements. * */ @Override public void removeAll() {
//TODO } /** * Remove elem at index * Return the removed element * Throws
IndexOutOfBoundsException if passed index is invalid. */ @Override public E removeIndex(int
index) { //TODO return null; } /** * Remove first matching element (where searchFct outputs true) *
Return the removed element * If no match, return null */ @Override public E
removeFirstMatching(Function<E, Boolean> searchFct) { //TODO return null; } //-----------------
Convenience Methods ------------------ /** Return this list as array * This method requires imports of:
* java.lang.reflect.Array; * java.util.concurrent.atomic.AtomicInteger; */ @Override
@SuppressWarnings("unchecked") public E[] toArray() { //This method is completed (no work
needed) if (this.isEmpty()) return (E[]) Array.newInstance(Object.class, 0); StructureIterator<E> iter
= this.iterator(); E[] array = (E[]) Array.newInstance(iter.peek().getClass(), this.size());
AtomicInteger counter = new AtomicInteger(0); this.forEach((each) ->
array[counter.getAndIncrement()] = each); return array; } /** * Returns one-line user-friendly
message about this object * Helpful method especially for debugging. */ @Override public String
toString() { //TODO return null; } /** Prints all elements to console, with newline after each */
@Override public void printAll() { //TODO } /** Iterates over elements in "this" object. For each
element, * performs actionFct (passing element being iterated on) * The generic type "? super E"
means some type that is * a superclass of E (inclusive) */ @Override public void
forEach(Consumer<? super E> actionFct) { //TODO } /** Return new list that is "this" list joined *
with "otherList" list (this list's elements are * first followed by the "otherList" list) */ @Override
public DynamicList<E> join(DynamicList<E> otherList) { //TODO return null; } //----------------- Utility
Methods ------------------ /** * Returns new DynamicList with "new elements". Each new element * is
generated from mapFct invoked with an element from * this list. */ @Override public <T>
DynamicList<T> map(Function<E, T> mapFct) { //TODO return null; } /** * Returns new
DynamicList containing only elements that * result in true when applied to selectFct * Returns new
DynamicList which is elements * selected from this list via selectFct */ @Override public
DynamicList<E> select(Function<E, Boolean> selectFct) { //TODO return null; } /** * Returns new
DynamicList which is this list * with elements rejected via rejectFct */ @Override public
3. DynamicList<E> reject(Function<E, Boolean> rejectFct) { //TODO return null; } /** Accumulate a
value by iterating over the collection * and accumulating during iteration. * E.g., accumulate a
"sum", or accumulate * a new collection which is the accumulation * of sub-collections obtained
from elements (think * of accumulating all players in a league by * accumulating the players from
each team */ @Override public <T> T accumulate(BiFunction<T, E, T> fct, T initialValue) { //TODO
return null; } //--------------------------------- // Public Constructors (Static Factory Constructor Methods)
// These three methods are completed for you /** Returns a new empty DynamicList */ public static
<T> DynamicList<T> newEmpty() { return new DynamicArray<>(); } /** Return a new empty
DynamicArray with "growthFactor" */ public static <T> DynamicList<T> fromGrowthFactor(double
growthFactor) { return new DynamicArray<>(growthFactor); } /** Return a new DynamicList that
contains all elements from the * param "aFixedArray" */ public static <T> DynamicList<T> from(T[]
aFixedArray) { DynamicList<T> dynamic = new DynamicArray<>(defaultGrowthFactor()); for (T
nextNewElem: aFixedArray) dynamic.add(nextNewElem); return dynamic; } //----------------------------
------------------------------ /*TODO - helper methods (optional -- coder's choice) Helper method simply
means any methods you add (your choice) to make coding easier (i.e., methods that "help" other
methods by doing some of the work. The other methods call the "helper methods". */ }