Question: Define the methods in each class Concrete class: DArray private int array[] public DArray() [constructor array size = 1, nAllocations = 1, nElements = 0]

Define the methods in each class

Concrete class: DArray

private int array[]
public DArray() [constructor array size = 1, nAllocations = 1, nElements = 0]

private void expandA()

--------------------------------

Interface: DArrayBehavior

public void append(int item) [add at the end]

public int getFirstItem()

public int getLastItem()

---------------------------------

Abstract Class: ArrayBP

Protected int numElements

Protected int numAllocations

public abstract void storeAt(int item, int index); public abstract int getFrom(int index);
public abstract int len(); [returns current length] public abstract void remove(); [removes last item] public abstract void removeAt(int index); [removes the item at the given index]

Followings should be implemented
inside the abstract class
public int getNumElements()
public int getNumAllocations()
public void setNumElements(int n)
public void setNumAllocations(int n)
public void increaseNumElements() [increase by 1] public void decreaseNumElements() [decrease by 1]

Dynamic array: Used to append integers in an empty list without creating an array with fixed sizes.
-append(int item) will append the item at the end of the array.

-If array is full, use expandA() to double the capacity.
-remove() will remove the last item, if any

-removeAt(int index) remove the item at index

Step by Step Solution

3.52 Rating (145 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public interface DArrayBehavior public void appendint item add at the end public int getFirstItem pu... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!